diff options
author | Andrej Valek <andrej.valek@siemens.com> | 2021-06-25 07:45:35 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-08 21:02:56 +0200 |
commit | ecac9853f29dcb2e5e0d70c0effaae2cabeefabf (patch) | |
tree | 4c42081fafbd0964c32fcd4c91d075bc9596cbf4 | |
parent | b198e9aa934386531b2bc1fd0291ed3cc6beaf96 (diff) | |
download | busybox-w32-ecac9853f29dcb2e5e0d70c0effaae2cabeefabf.tar.gz busybox-w32-ecac9853f29dcb2e5e0d70c0effaae2cabeefabf.tar.bz2 busybox-w32-ecac9853f29dcb2e5e0d70c0effaae2cabeefabf.zip |
mktemp: add --tmpdir option
Make mktemp more compatible with coreutils.
- add "--tmpdir" option
- add long variants for "d,q,u" options
Note: Upstream ca-certificate update script started using this option.
function old new delta
.rodata 104179 104219 +40
mktemp_main 186 194 +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 48/0) Total: 48 bytes
Signed-off-by: Andrej Valek <andrej.valek@siemens.com>
Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/mktemp.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c index 5393320a5..33e2720de 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c | |||
@@ -72,13 +72,27 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
72 | OPT_t = 1 << 2, | 72 | OPT_t = 1 << 2, |
73 | OPT_p = 1 << 3, | 73 | OPT_p = 1 << 3, |
74 | OPT_u = 1 << 4, | 74 | OPT_u = 1 << 4, |
75 | OPT_tmpdir = (1 << 5) * ENABLE_LONG_OPTS, | ||
75 | }; | 76 | }; |
76 | 77 | ||
77 | path = getenv("TMPDIR"); | 78 | path = getenv("TMPDIR"); |
78 | if (!path || path[0] == '\0') | 79 | if (!path || path[0] == '\0') |
79 | path = "/tmp"; | 80 | path = "/tmp"; |
80 | 81 | ||
82 | #if ENABLE_LONG_OPTS | ||
83 | opts = getopt32long(argv, "^" | ||
84 | "dqtp:u" | ||
85 | "\0" | ||
86 | "?1" /* 1 arg max */, | ||
87 | "directory\0" No_argument "d" | ||
88 | "quiet\0" No_argument "q" | ||
89 | "dry-run\0" No_argument "u" | ||
90 | "tmpdir\0" Optional_argument "\xff" | ||
91 | , &path, &path | ||
92 | ); | ||
93 | #else | ||
81 | opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path); | 94 | opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path); |
95 | #endif | ||
82 | 96 | ||
83 | chp = argv[optind]; | 97 | chp = argv[optind]; |
84 | if (!chp) { | 98 | if (!chp) { |
@@ -95,7 +109,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
95 | goto error; | 109 | goto error; |
96 | } | 110 | } |
97 | #endif | 111 | #endif |
98 | if (opts & (OPT_t|OPT_p)) | 112 | if (opts & (OPT_t|OPT_p|OPT_tmpdir)) |
99 | chp = concat_path_file(path, chp); | 113 | chp = concat_path_file(path, chp); |
100 | 114 | ||
101 | if (opts & OPT_u) { | 115 | if (opts & OPT_u) { |