diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-13 17:38:34 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-13 17:38:34 +0100 |
commit | 4ed3c52ce9b3ce5604c4fa075fda374f8cd01eea (patch) | |
tree | a8ea24dc52ac00ed72df6d64d43f0076acae9887 /debianutils | |
parent | 07cda2268a6cff59378af16eabc4968d9bebe915 (diff) | |
download | busybox-w32-4ed3c52ce9b3ce5604c4fa075fda374f8cd01eea.tar.gz busybox-w32-4ed3c52ce9b3ce5604c4fa075fda374f8cd01eea.tar.bz2 busybox-w32-4ed3c52ce9b3ce5604c4fa075fda374f8cd01eea.zip |
mktemp: make it more compatible with GNU coreutils 8.4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/mktemp.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 86881f86d..f4961af59 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
@@ -31,6 +31,25 @@ | |||
31 | * -p; else /tmp [deprecated] | 31 | * -p; else /tmp [deprecated] |
32 | */ | 32 | */ |
33 | 33 | ||
34 | //usage:#define mktemp_trivial_usage | ||
35 | //usage: "[-dt] [-p DIR] [TEMPLATE]" | ||
36 | //usage:#define mktemp_full_usage "\n\n" | ||
37 | //usage: "Create a temporary file with name based on TEMPLATE and print its name.\n" | ||
38 | //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n" | ||
39 | //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n" | ||
40 | //usage: "\nOptions:" | ||
41 | //usage: "\n -d Make directory, not file" | ||
42 | ////usage: "\n -q Fail silently on errors" - we ignore this opt | ||
43 | //usage: "\n -t Prepend base directory name to TEMPLATE" | ||
44 | //usage: "\n -p DIR Use DIR as a base directory (implies -t)" | ||
45 | //usage: "\n" | ||
46 | //usage: "\nBase directory is: -p DIR, else $TMPDIR, else /tmp" | ||
47 | //usage: | ||
48 | //usage:#define mktemp_example_usage | ||
49 | //usage: "$ mktemp /tmp/temp.XXXXXX\n" | ||
50 | //usage: "/tmp/temp.mWiLjM\n" | ||
51 | //usage: "$ ls -la /tmp/temp.mWiLjM\n" | ||
52 | //usage: "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" | ||
34 | 53 | ||
35 | #include "libbb.h" | 54 | #include "libbb.h" |
36 | 55 | ||
@@ -40,20 +59,33 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
40 | const char *path; | 59 | const char *path; |
41 | char *chp; | 60 | char *chp; |
42 | unsigned opts; | 61 | unsigned opts; |
62 | enum { | ||
63 | OPT_d = 1 << 0, | ||
64 | OPT_q = 1 << 1, | ||
65 | OPT_t = 1 << 2, | ||
66 | OPT_p = 1 << 3, | ||
67 | }; | ||
43 | 68 | ||
44 | path = getenv("TMPDIR"); | 69 | path = getenv("TMPDIR"); |
45 | if (!path || path[0] == '\0') | 70 | if (!path || path[0] == '\0') |
46 | path = "/tmp"; | 71 | path = "/tmp"; |
47 | 72 | ||
48 | /* -q and -t are ignored */ | 73 | /* -q is ignored */ |
49 | opt_complementary = "?1"; /* 1 argument max */ | 74 | opt_complementary = "?1"; /* 1 argument max */ |
50 | opts = getopt32(argv, "dqtp:", &path); | 75 | opts = getopt32(argv, "dqtp:", &path); |
51 | 76 | ||
52 | chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX"); | 77 | chp = argv[optind]; |
53 | if (!strchr(chp, '/') || (opts & 8)) | 78 | if (!chp) { |
79 | /* GNU coreutils 8.4: | ||
80 | * bare "mktemp" -> "mktemp -t tmp.XXXXXX" | ||
81 | */ | ||
82 | chp = xstrdup("tmp.XXXXXX"); | ||
83 | opts |= OPT_t; | ||
84 | } | ||
85 | if (opts & (OPT_t|OPT_p)) | ||
54 | chp = concat_path_file(path, chp); | 86 | chp = concat_path_file(path, chp); |
55 | 87 | ||
56 | if (opts & 1) { /* -d */ | 88 | if (opts & OPT_d) { |
57 | if (mkdtemp(chp) == NULL) | 89 | if (mkdtemp(chp) == NULL) |
58 | return EXIT_FAILURE; | 90 | return EXIT_FAILURE; |
59 | } else { | 91 | } else { |