[hackers] [sbase] Audit mktemp(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 17 Mar 2015 11:22:42 +0100 (CET)

commit f724e87cc51c58404983439650f03851c897172f
Author: FRIGN <dev_AT_frign.de>
Date: Tue Mar 17 11:01:33 2015 +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.

diff --git a/README b/README
index c936841..7c29823 100644
--- a/README
+++ b/README
_AT_@ -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
index 08796cd..8dbb210 100644
--- a/mktemp.c
+++ b/mktemp.c
_AT_@ -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':
_AT_@ -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;
 }
Received on Tue Mar 17 2015 - 11:22:42 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 17 2015 - 11:24:28 CET