A couple more stylistic changes to uudecode(1)

This commit is contained in:
sin 2014-02-04 14:44:43 +00:00
parent ed9985205b
commit bf2b270946

View File

@ -40,23 +40,19 @@ main(int argc, char *argv[])
if (argc == 0) { if (argc == 0) {
checkheader(stdin, "<stdin>", "begin ", &mode, &fname); checkheader(stdin, "<stdin>", "begin ", &mode, &fname);
nfp = checkfile(fname); if ((nfp = checkfile(fname)) == NULL)
if (nfp == NULL)
eprintf("fopen %s:", fname); eprintf("fopen %s:", fname);
uudecode(stdin, nfp); uudecode(stdin, nfp);
fclose(nfp); fclose(nfp);
} else { } else {
if (!(fp = fopen(argv[0], "r"))) if ((fp = fopen(argv[0], "r")) == NULL)
eprintf("fopen %s:", argv[0]); eprintf("fopen %s:", argv[0]);
checkheader(fp, argv[0], "begin ", &mode, &fname); checkheader(fp, argv[0], "begin ", &mode, &fname);
nfp = checkfile(fname); if ((nfp = checkfile(fname)) == NULL)
if (nfp == NULL) {
fclose(fp);
eprintf("fopen %s:", fname); eprintf("fopen %s:", fname);
}
uudecode(fp, nfp); uudecode(fp, nfp);
fclose(fp);
fclose(nfp); fclose(nfp);
fclose(fp);
} }
if (fchmod(fileno(nfp), mode) < 0) if (fchmod(fileno(nfp), mode) < 0)
eprintf("chmod %s:", fname); eprintf("chmod %s:", fname);
@ -126,9 +122,8 @@ checkmode(const char *str,mode_t *validmode)
if (str == NULL || str == '\0') if (str == NULL || str == '\0')
eprintf("invalid mode\n"); eprintf("invalid mode\n");
octal = strtol(str, &end, 8); octal = strtol(str, &end, 8);
if (*end == '\0') { /* successful conversion from a valid str */ if (*end == '\0') {
if (octal >= 0 && octal <= 07777) { if (octal >= 0 && octal <= 07777) {
if(octal & 04000) *validmode |= S_ISUID; if(octal & 04000) *validmode |= S_ISUID;
if(octal & 02000) *validmode |= S_ISGID; if(octal & 02000) *validmode |= S_ISGID;
@ -142,7 +137,6 @@ checkmode(const char *str,mode_t *validmode)
if(octal & 00004) *validmode |= S_IROTH; if(octal & 00004) *validmode |= S_IROTH;
if(octal & 00002) *validmode |= S_IWOTH; if(octal & 00002) *validmode |= S_IWOTH;
if(octal & 00001) *validmode |= S_IXOTH; if(octal & 00001) *validmode |= S_IXOTH;
*validmode &= 07777;
} }
} }
} }
@ -167,7 +161,8 @@ uudecode(FILE *fp, FILE *outfp)
*nl = '\0'; *nl = '\0';
else else
eprintf("no newline found, aborting\n"); eprintf("no newline found, aborting\n");
if ((i = DEC(*p)) <= 0) /* check for last line */ /* check for last line */
if ((i = DEC(*p)) <= 0)
break; break;
for (++p; i > 0; p += 4, i -= 3) { for (++p; i > 0; p += 4, i -= 3) {
if (i >= 3) { if (i >= 3) {