sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 1b7155943196afcde33b4d3ce235fa2786c02d9a
parent 4af8889396924ab79f75c6042886780e06102360
Author: FRIGN <dev@frign.de>
Date:   Wed Mar 18 00:10:36 +0100

Audit uudecode(1)

Style cleanup, Manpage refactoring.

Diffstat:
README | 2+-
uudecode.1 | 24++++++++++++++----------
uudecode.c | 19++++++++-----------
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/README b/README @@ -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 diff --git a/uudecode.1 b/uudecode.1 @@ -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 diff --git a/uudecode.c b/uudecode.c @@ -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 {