[Toybox] [PATCH] mktemp: add -t and fix behavior.
Rob Landley
rob at landley.net
Wed Nov 28 17:19:42 PST 2018
On 11/28/18 6:15 PM, enh via Toybox wrote:
> The new tests pass on the host (coreutils 8.28) and with toybox after
> 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 (!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
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...
Rob
More information about the Toybox
mailing list