Fix bug introduced by last commit (print template instead of toybuf).
authorRob Landley <rob@landley.net>
Thu, 12 Feb 2015 22:41:59 +0000 (16:41 -0600)
committerRob Landley <rob@landley.net>
Thu, 12 Feb 2015 22:41:59 +0000 (16:41 -0600)
Also, xstrdup() the unmodified template because changing the environment string
could make the changed version show up in "ps".

toys/lsb/mktemp.c

index f756ffe..cc42665 100644 (file)
@@ -40,11 +40,14 @@ void mktemp_main(void)
   if (!TT.tmpdir) TT.tmpdir = getenv("TMPDIR");
   if (!TT.tmpdir) TT.tmpdir = "/tmp";
 
-  if (!strchr(template, '/')) template = xmprintf("%s/%s", TT.tmpdir, template);
+  template = strchr(template, '/') ? xstrdup(template)
+             : xmprintf("%s/%s", TT.tmpdir, template);
 
   if (d_flag ? !mkdtemp(template) : mkstemp(template) == -1) {
     if (toys.optflags & FLAG_q) toys.exitval = 1;
     else perror_exit("Failed to create %s %s/%s",
                      d_flag ? "directory" : "file", TT.tmpdir, template);
-  } else xputs(toybuf);
+  } else xputs(template);
+
+  if (CFG_TOYBOX_FREE) free(template);
 }