aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-09-03 21:24:46 -0500
committerRob Landley <rob@landley.net>2012-09-03 21:24:46 -0500
commitb0e87ff287ca6938b9450a61cb6134fba6309b37 (patch)
treecbb0f3f4bc0a73306ca08a53e7cd8bde4e7d1185 /toys/lsb
parentee429cfcb22d0c0920c848af9a6e2b8cb442b249 (diff)
downloadtoybox-b0e87ff287ca6938b9450a61cb6134fba6309b37.tar.gz
mktemp broke kernel build, so new rules: if you don't specify anything, /tmp/tmp.* Specify a file, ./file. Specify -p dir then dir/tmp.*. Specify -p dir and file, dir/file. Also implement -q which lsb wants.
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/mktemp.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index d6234ee8..c42588ab 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -6,21 +6,20 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mktemp.html
-USE_MKTEMP(NEWTOY(mktemp, ">1(directory)d(tmpdir)p:", TOYFLAG_BIN))
+USE_MKTEMP(NEWTOY(mktemp, ">1q(directory)d(tmpdir)p:", TOYFLAG_BIN))
config MKTEMP
bool "mktemp"
default y
help
- usage: mktemp [OPTION] [TEMPLATE]
+ usage: mktemp [-dq] [-p DIR] [TEMPLATE]
- Safely create a temporary file or directory and print its name.
- TEMPLATE should end in 6 consecutive X's, the default
- template is tmp.XXXXXX and the default directory is /tmp/.
-
- -d, --directory Create a directory, instead of a file
- -p DIR, --tmpdir=DIR Use DIR as a base path
+ Safely create new file and print its name. Default TEMPLATE is
+ /tmp/tmp.XXXXXX and each trailing X is replaced with random char.
+ -d, --directory Create directory instead of file
+ -p DIR, --tmpdir=DIR Put new file in DIR
+ -q Quiet
*/
#include "toys.h"
@@ -28,27 +27,33 @@ config MKTEMP
DEFINE_GLOBALS(
char * tmpdir;
)
+
+#define FLAG_p 1
+#define FLAG_d 2
+#define FLAG_q 4
+
#define TT this.mktemp
void mktemp_main(void)
{
- int d_flag = toys.optflags & 2;
- char *tmp, *path;
+ int d_flag = toys.optflags & FLAG_d;
+ char *tmp;
tmp = *toys.optargs;
- if (!tmp) tmp = "tmp.XXXXXX";
- if (!TT.tmpdir) TT.tmpdir = "/tmp/";
- tmp = xmsprintf("%s/%s", TT.tmpdir, tmp);
+ if (!tmp) {
+ if (!TT.tmpdir) TT.tmpdir = "/tmp";
+ tmp = "tmp.xxxxxx";
+ }
+ if (TT.tmpdir) tmp = xmsprintf("%s/%s", TT.tmpdir ? TT.tmpdir : "/tmp",
+ *toys.optargs ? *toys.optargs : "tmp.XXXXXX");
if (d_flag ? mkdtemp(tmp) == NULL : mkstemp(tmp) == -1)
- perror_exit("Failed to create temporary %s",
- d_flag ? "directory" : "file");
+ if (toys.optflags & FLAG_q)
+ perror_exit("Failed to create temporary %s",
+ d_flag ? "directory" : "file");
- xputs(path = xrealpath(tmp));
+ xputs(tmp);
- if (CFG_TOYBOX_FREE) {
- free(path);
- free(tmp);
- }
+ if (CFG_TOYBOX_FREE && TT.tmpdir) free(tmp);
}