Rob Landley
2018-11-29 01:19:42 UTC
The new tests pass on the host (coreutils 8.28) and with toybox after
this patch is applied.
...this patch is applied.
- if (!template) template = "tmp.XXXXXX";
+ if (!template) {
+ toys.optflags |= FLAG_t;
+ template = "tmp.XXXXXXXXXX";
+ }
- if (!TT.p) TT.p = getenv("TMPDIR");
+ if (!TT.p || (toys.optflags & FLAG_t)) TT.p = getenv("TMPDIR");
What happens if you specify -p and -t together?+ if (!template) {
+ toys.optflags |= FLAG_t;
+ template = "tmp.XXXXXXXXXX";
+ }
- if (!TT.p) TT.p = getenv("TMPDIR");
+ if (!TT.p || (toys.optflags & FLAG_t)) TT.p = getenv("TMPDIR");
if (!TT.p || !*TT.p) TT.p = "/tmp";
- template = strchr(template, '/') ? xstrdup(template)
- : xmprintf("%s/%s", TT.p, template);
+ // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
+ template = (strchr(template, '/') || !(toys.optflags & (FLAG_p|FLAG_t)))
+ ? xstrdup(template) : xmprintf("%s/%s", TT.p, template);
I used to have xrealpath() but then I had to make xabspath to implement all the- template = strchr(template, '/') ? xstrdup(template)
- : xmprintf("%s/%s", TT.p, template);
+ // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
+ template = (strchr(template, '/') || !(toys.optflags & (FLAG_p|FLAG_t)))
+ ? xstrdup(template) : xmprintf("%s/%s", TT.p, template);
readlink options (the libc one didn't _quite_ let me get in there and specify
the behavior, so I had to reinvent the wheel), and I just use that now.
if (toys.optflags & FLAG_q) toys.exitval = 1;
else perror_exit("Failed to create %s %s/%s",
- d_flag ? "directory" : "file", TT.p, template);
+ toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
Sigh. I should do a FLAG(d) macro...else perror_exit("Failed to create %s %s/%s",
- d_flag ? "directory" : "file", TT.p, template);
+ toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
Rob