mirror of
git://git.suckless.org/sbase
synced 2024-12-21 22:50:16 +00:00
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:
parent
683d108387
commit
a76d4943b5
2
README
2
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
|
||||
|
16
mktemp.c
16
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user