aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-09-17 06:00:14 -0500
committerRob Landley <rob@landley.net>2019-09-17 06:00:14 -0500
commit0dedd13253f4e3fc4ddaf912f503b30261d2ee63 (patch)
tree1088306acbfab223bd4af9bf3ba6421a61e38127 /toys/lsb
parent861d1c76cd2ddf3c2feab0cd439f325b96541610 (diff)
downloadtoybox-0dedd13253f4e3fc4ddaf912f503b30261d2ee63.tar.gz
Allow --tmpdir's argument to be optional.
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/mktemp.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 22c880fa..0986b4fd 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -4,7 +4,7 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mktemp.html
-USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):t", TOYFLAG_BIN))
+USE_MKTEMP(NEWTOY(mktemp, ">1(tmpdir);:uqd(directory)p:t", TOYFLAG_BIN))
config MKTEMP
bool "mktemp"
@@ -28,14 +28,20 @@ config MKTEMP
#include "toys.h"
GLOBALS(
- char *p;
+ char *p, *tmpdir;
)
void mktemp_main(void)
{
- char *template = *toys.optargs, *dir = TT.p, *te = getenv("TMPDIR");
+ char *template = *toys.optargs, *dir, *te = getenv("TMPDIR");
int len;
+ // --tmpdir's argument is optional's but -p is mandatory, so can't combine
+ if (!TT.p && FLAG(tmpdir)) {
+ TT.p = TT.tmpdir ? TT.tmpdir : "";
+ toys.optflags |= FLAG_p;
+ }
+ dir = TT.p;
// if template, no prefix unless -pt. if !template, always prefix
if (!dir || !*dir || (FLAG(t) && te && *te)) dir = te;
if (!dir || !*dir) dir = "/tmp";
@@ -52,7 +58,7 @@ void mktemp_main(void)
// In theory you just xputs(mktemp(template)) for -u, in practice there's
// link-time deprecation warnings if you do that. So we fake up our own:
- if (toys.optflags & FLAG_u) {
+ if (FLAG(u)) {
long long rr;
char *s = template+len;
@@ -72,12 +78,12 @@ void mktemp_main(void)
if (*s>'Z') (*s) += 6;
rr>>=6;
}
- } else if ((toys.optflags & FLAG_d) ? !mkdtemp(template) : mkstemp(template) == -1) {
- if (toys.optflags & FLAG_q) {
+ } else if (FLAG(d) ? !mkdtemp(template) : mkstemp(template) == -1) {
+ if (FLAG(q)) {
toys.exitval = 1;
return;
- } else perror_exit("Failed to create %s %s/%s",
- (toys.optflags & FLAG_d) ? "directory" : "file", TT.p, template);
+ } else perror_exit("Failed to create %s %s",
+ FLAG(d) ? "directory" : "file", template);
}
xputs(template);