diff options
author | Denys Vlasenko | 2010-06-18 03:16:27 +0200 |
---|---|---|
committer | Denys Vlasenko | 2010-06-18 03:16:27 +0200 |
commit | 9b814ca6335806a6eb47e22805620ec81d5d849d (patch) | |
tree | 37f70b9da97e9714227b536811be47f4f7fd3959 /debianutils | |
parent | 4ebdae3777b8c9175d5d07090989f7e498befc42 (diff) | |
download | busybox-9b814ca6335806a6eb47e22805620ec81d5d849d.zip busybox-9b814ca6335806a6eb47e22805620ec81d5d849d.tar.gz |
mktemp: be more compatible: bare "mktemp" creates tempfile in /tmp, not cwd
function old new delta
mktemp_main 171 152 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/mktemp.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 0dcb1e8..c402114 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c @@ -39,23 +39,20 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) { const char *path; char *chp; - unsigned opt; + unsigned opts; + path = getenv("TMPDIR"); + if (!path || path[0] == '\0') + path = "/tmp"; + + /* -q and -t are ignored */ opt_complementary = "?1"; /* 1 argument max */ - opt = getopt32(argv, "dqtp:", &path); - chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX"); + opts = getopt32(argv, "dqtp:", &path); - if (opt & (4|8)) { /* -t and/or -p */ - const char *dir = getenv("TMPDIR"); - if (dir && *dir != '\0') - path = dir; - else if (!(opt & 8)) /* no -p */ - path = "/tmp/"; - /* else path comes from -p DIR */ - chp = concat_path_file(path, chp); - } + chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX"); + chp = concat_path_file(path, chp); - if (opt & 1) { /* -d */ + if (opts & 1) { /* -d */ if (mkdtemp(chp) == NULL) return EXIT_FAILURE; } else { |