Audit uudecode(1)

Style cleanup, Manpage refactoring.
This commit is contained in:
FRIGN 2015-03-18 00:10:36 +01:00
parent 4af8889396
commit 1b71559431
3 changed files with 23 additions and 22 deletions

2
README
View File

@ -84,7 +84,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
#*| unexpand yes none
=*| uniq yes none
=*| unlink yes none
=* uudecode yes none
=*| uudecode yes none
=* uuencode yes none
#* wc yes none
= xargs no -I, -L, -p, -s, -t, -x

View File

@ -1,4 +1,4 @@
.Dd February 13, 2015
.Dd March 18, 2015
.Dt UUDECODE 1
.Os sbase
.Sh NAME
@ -13,23 +13,27 @@
.Nm
reads
.Ar file
(or by default, the standard input) and writes a decoded
version to the file specified in the uuencoded header. In case that
the file already exists, it is truncated. Otherwise a new file is
created. After the operation the permissions of the created/accessed
are changed to reflect the mode in the header.
and writes a decoded version to the file specified in the uuencoded header.
In case the file already exists, it is truncated. Otherwise a new file is
created. The permissions of the created/accessed file are changed to
reflect the mode in the header.
If no
.Ar file
is given
.Nm
reads from stdin.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl m
Use Base64 for decoding.
.It Fl o Ar output
Use the file specified by
Write to
.Ar output
instead of standard output.
rather than the file specified in the header.
.El
.Sh IMPLEMENTATION NOTES
For safety currently uudecode operates only on regular files and
stdout. Trying to uudecode to a link, directory, or special file
For safety uudecode operates on regular files and stdout only.
Trying to uudecode to a link, directory, or special file
yields an error.
.Sh SEE ALSO
.Xr uuencode 1

View File

@ -17,7 +17,7 @@ parsefile(const char *fname)
struct stat st;
int ret;
if (strcmp(fname, "/dev/stdout") == 0 || strcmp(fname, "-") == 0)
if (!strcmp(fname, "/dev/stdout") || !strcmp(fname, "-"))
return stdout;
ret = lstat(fname, &st);
/* if it is a new file, try to open it */
@ -32,12 +32,11 @@ parsefile(const char *fname)
return NULL;
}
tropen:
return fopen(fname,"w");
return fopen(fname, "w");
}
static void
parseheader(FILE *fp, const char *s, char **header, mode_t *mode,
char **fname)
parseheader(FILE *fp, const char *s, char **header, mode_t *mode, char **fname)
{
char bufs[PATH_MAX + 18]; /* len header + mode + maxname */
char *p, *q;
@ -74,8 +73,8 @@ parseheader(FILE *fp, const char *s, char **header, mode_t *mode,
static const char b64dt[] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,
7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
52,53,54,55,56,57,58,59,60,61,-1,-1,-1, 0,-1,-1,-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
49,50,51,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@ -212,7 +211,7 @@ uudecode(FILE *fp, FILE *outfp)
}
/* check for end or fail */
len = getline(&bufb, &n, fp);
if (len < 3 || strncmp(bufb, "end", 3) != 0 || bufb[3] != '\n')
if (len < 3 || strncmp(bufb, "end", 3) || bufb[3] != '\n')
eprintf("invalid uudecode footer \"end\" not found\n");
free(bufb);
}
@ -227,11 +226,9 @@ int
main(int argc, char *argv[])
{
FILE *fp = NULL, *nfp = NULL;
char *fname, *header;
const char *ifname;
mode_t mode = 0;
char *fname, *header, *ifname, *ofname = NULL;
void (*d) (FILE *, FILE *) = NULL;
char *ofname = NULL;
ARGBEGIN {
case 'm':
@ -248,7 +245,7 @@ main(int argc, char *argv[])
if (argc > 1)
usage();
if (argc == 0) {
if (!argc) {
fp = stdin;
ifname = "<stdin>";
} else {