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
=*| 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

View File

@ -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;
}