diff options
author | Rob Landley <rob@landley.net> | 2015-02-07 19:45:23 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-02-07 19:45:23 -0600 |
commit | 6434acef74318e8c3f7e68f4513112b95d2979e8 (patch) | |
tree | 29b738b92633a2ab04c3c68f0b1f10111a9df096 /toys | |
parent | 831a085a8d36cfb4fa064bdddb6bd0a434d4b3e1 (diff) | |
download | toybox-6434acef74318e8c3f7e68f4513112b95d2979e8.tar.gz |
Shameless meddling.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/lsb/mktemp.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c index 52e53ee6..498f9f1c 100644 --- a/toys/lsb/mktemp.c +++ b/toys/lsb/mktemp.c @@ -12,44 +12,39 @@ config MKTEMP help usage: mktemp [-dq] [-p DIR] [TEMPLATE] - Safely create a new file and print its name. The default TEMPLATE is - tmp.XXXXXX. The default DIR is $TMPDIR, or /tmp if $TMPDIR is not set. + Safely create a new file "DIR/TEMPLATE" and print its name. - -d, --directory Create directory instead of file - -p DIR, --tmpdir=DIR Put new file in DIR - -q Quiet + -d Create directory instead of file (--directory) + -p Put new file in DIR (--tmpdir) + -q Quiet, no error messages + + Each X in TEMPLATE is replaced with a random printable character. The + default TEMPLATE is tmp.XXXXXX, and the default DIR is $TMPDIR if set, + else "/tmp". */ #define FOR_mktemp #include "toys.h" GLOBALS( - char * tmpdir; + char *tmpdir; ) void mktemp_main(void) { int d_flag = toys.optflags & FLAG_d; char *template = *toys.optargs; - int success; - if (!template) { - template = "tmp.XXXXXX"; - } + if (!template) template = "tmp.XXXXXX"; if (!TT.tmpdir) TT.tmpdir = getenv("TMPDIR"); if (!TT.tmpdir) TT.tmpdir = "/tmp"; snprintf(toybuf, sizeof(toybuf), "%s/%s", TT.tmpdir, template); - if (d_flag ? mkdtemp(toybuf) == NULL : mkstemp(toybuf) == -1) { - if (toys.optflags & FLAG_q) { - toys.exitval = 1; - } else { - perror_exit("Failed to create temporary %s with template %s/%s", - d_flag ? "directory" : "file", TT.tmpdir, template); - } - } - - xputs(toybuf); + if (d_flag ? !mkdtemp(toybuf) : mkstemp(toybuf) == -1) { + if (toys.optflags & FLAG_q) toys.exitval = 1; + else perror_exit("Failed to create %s %s/%s", + d_flag ? "directory" : "file", TT.tmpdir, template); + } else xputs(toybuf); } |