aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorKylie McClain <somasis@exherbo.org>2015-12-24 00:20:24 -0500
committerRob Landley <rob@landley.net>2015-12-30 20:49:57 -0600
commit46ddb5520731aaf578de9d620f894395fb9d58b6 (patch)
tree7fb6530ef3dafe5d0f610ef6d1320072c5552e80 /toys/lsb
parent08dc20ad276251f61a9a4036f9d17ee601a4b3a0 (diff)
downloadtoybox-46ddb5520731aaf578de9d620f894395fb9d58b6.tar.gz
lsb/mktemp: Add -u flag
The -u flag creates a file, and unlinks it before exiting. This is usually known as "unsafe mode", or "dry-run" mode. GNU mktemp has it, as does Busybox's mktemp and likely many others.
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/mktemp.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index cee62c1d..f1f9d885 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -4,19 +4,20 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mktemp.html
-USE_MKTEMP(NEWTOY(mktemp, ">1qd(directory)p(tmpdir):", TOYFLAG_BIN))
+USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):", TOYFLAG_BIN))
config MKTEMP
bool "mktemp"
default y
help
- usage: mktemp [-dq] [-p DIR] [TEMPLATE]
+ usage: mktemp [-dqu] [-p DIR] [TEMPLATE]
Safely create a new file "DIR/TEMPLATE" and print its name.
-d Create directory instead of file (--directory)
-p Put new file in DIR (--tmpdir)
-q Quiet, no error messages
+ -u Don't create anything, just print what would be created
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,
@@ -48,6 +49,7 @@ void mktemp_main(void)
else perror_exit("Failed to create %s %s/%s",
d_flag ? "directory" : "file", TT.tmpdir, template);
} else xputs(template);
+ if (toys.optflags & FLAG_u) unlink(template);
if (CFG_TOYBOX_FREE) free(template);
}