Audit mktemp(1)

1) Unglobalize variables.
2) Sort local variables.
3) Use return instead of exit() in main().
4) Add empty line before return.
This commit is contained in:
FRIGN 2015-03-17 11:01:33 +01:00
parent 683d108387
commit a76d4943b5
2 changed files with 8 additions and 10 deletions

2
README
View File

@ -46,7 +46,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=*| md5sum non-posix none =*| md5sum non-posix none
=*| mkdir yes none =*| mkdir yes none
=*| mkfifo yes none =*| mkfifo yes none
=* mktemp non-posix none =*| mktemp non-posix none
=*| mv yes none (-i) =*| mv yes none (-i)
=*| nice yes none =*| nice yes none
= nl no -d, -f, -h, -p = nl no -d, -f, -h, -p

View File

@ -12,16 +12,13 @@ usage(void)
eprintf("usage: %s [-dq] [template]\n", argv0); eprintf("usage: %s [-dq] [template]\n", argv0);
} }
static int dflag = 0;
static int qflag = 0;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *template = "tmp.XXXXXXXXXX"; int dflag = 0, qflag = 0, fd;
char *tmpdir = "/tmp", *p; char *template = "tmp.XXXXXXXXXX",
char path[PATH_MAX], tmp[PATH_MAX]; *tmpdir = "/tmp", *p,
int fd; path[PATH_MAX], tmp[PATH_MAX];
ARGBEGIN { ARGBEGIN {
case 'd': case 'd':
@ -61,16 +58,17 @@ main(int argc, char *argv[])
if (!mkdtemp(path)) { if (!mkdtemp(path)) {
if (!qflag) if (!qflag)
eprintf("mkdtemp %s:", path); eprintf("mkdtemp %s:", path);
exit(1); return 1;
} }
} else { } else {
if ((fd = mkstemp(path)) < 0) { if ((fd = mkstemp(path)) < 0) {
if (!qflag) if (!qflag)
eprintf("mkstemp %s:", path); eprintf("mkstemp %s:", path);
exit(1); return 1;
} }
close(fd); close(fd);
} }
puts(path); puts(path);
return 0; return 0;
} }