sbase

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

commit a76d4943b50ccea6b8b35e7b60fb8c2fc1254315
parent 683d108387cb8e7ac7fdaa03fab77b41a8ba5d44
Author: FRIGN <dev@frign.de>
Date:   Tue Mar 17 11:01:33 +0100

Audit mktemp(1)

1) Unglobalize variables.
2) Sort local variables.
3) Use return instead of exit() in main().
4) Add empty line before return.

Diffstat:
README | 2+-
mktemp.c | 16+++++++---------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/README b/README @@ -46,7 +46,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =*| md5sum non-posix none =*| mkdir yes none =*| mkfifo yes none -=* mktemp non-posix none +=*| mktemp non-posix none =*| mv yes none (-i) =*| nice yes none = nl no -d, -f, -h, -p diff --git a/mktemp.c b/mktemp.c @@ -12,16 +12,13 @@ usage(void) eprintf("usage: %s [-dq] [template]\n", argv0); } -static int dflag = 0; -static int qflag = 0; - int main(int argc, char *argv[]) { - char *template = "tmp.XXXXXXXXXX"; - char *tmpdir = "/tmp", *p; - char path[PATH_MAX], tmp[PATH_MAX]; - int fd; + int dflag = 0, qflag = 0, fd; + char *template = "tmp.XXXXXXXXXX", + *tmpdir = "/tmp", *p, + path[PATH_MAX], tmp[PATH_MAX]; ARGBEGIN { case 'd': @@ -61,16 +58,17 @@ main(int argc, char *argv[]) if (!mkdtemp(path)) { if (!qflag) eprintf("mkdtemp %s:", path); - exit(1); + return 1; } } else { if ((fd = mkstemp(path)) < 0) { if (!qflag) eprintf("mkstemp %s:", path); - exit(1); + return 1; } close(fd); } puts(path); + return 0; }