summaryrefslogtreecommitdiff
authorTanguy Pruvot <tanguy.pruvot@gmail.com>2013-07-31 19:43:02 (GMT)
committer Tanguy Pruvot <tanguy.pruvot@gmail.com>2013-07-31 19:43:02 (GMT)
commitc7dcb61ebd7d9618a00fb9177f2d9056d745899f (patch)
treefcbc732764ad620ef74cc677753d9012278e3ba9
parenta9a9b985f0768c47d12869257d56341abb182e54 (diff)
downloadbusybox-c7dcb61ebd7d9618a00fb9177f2d9056d745899f.zip
busybox-c7dcb61ebd7d9618a00fb9177f2d9056d745899f.tar.gz
busybox-c7dcb61ebd7d9618a00fb9177f2d9056d745899f.tar.bz2
mktemp: unlink mkstemp alternative to (unsafe) dry-run option
Change-Id: I19eeca4e8a915418527630105405c4d74d542ead
Diffstat
-rw-r--r--debianutils/mktemp.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c
index 92b8790..f9f067b 100644
--- a/debianutils/mktemp.c
+++ b/debianutils/mktemp.c
@@ -43,7 +43,7 @@
//usage: "\n -p DIR Use DIR as a base directory (implies -t)"
//usage: "\n -u Do not create anything; print a name"
//usage: "\n"
-//usage: "\nBase directory is: -p DIR, else $TMPDIR, else /tmp"
+//usage: "\nBase directory is: -p DIR, else $TMPDIR, else /data/local/tmp"
//usage:
//usage:#define mktemp_example_usage
//usage: "$ mktemp /tmp/temp.XXXXXX\n"
@@ -69,7 +69,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
path = getenv("TMPDIR");
if (!path || path[0] == '\0')
- path = "/tmp";
+ path = "/data/local/tmp";
opt_complementary = "?1"; /* 1 argument max */
opts = getopt32(argv, "dqtp:u", &path);
@@ -93,9 +93,17 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
chp = concat_path_file(path, chp);
if (opts & OPT_u) {
- chp = mkstemp(chp);
- if (chp[0] == '\0')
+#ifdef __BIONIC__
+ int fd = mkstemp(chp);
+ if (fd < 0)
goto error;
+
+ /* unlink created file */
+ close(fd);
+ unlink(chp);
+#else
+ chp = mktemp(chp);
+#endif
} else if (opts & OPT_d) {
if (mkdtemp(chp) == NULL)
goto error;