diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-04-17 16:00:20 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-04-17 16:00:20 +0200 |
| commit | 75e1e7b3d538fa1a2396cd36122e0be702931345 (patch) | |
| tree | 545494d4c614ab8c5e9305d03001c9c8ee5174bd /debianutils | |
| parent | 176bc344751dfc41e87976182381ae0560c94f22 (diff) | |
| download | busybox-w32-75e1e7b3d538fa1a2396cd36122e0be702931345.tar.gz busybox-w32-75e1e7b3d538fa1a2396cd36122e0be702931345.tar.bz2 busybox-w32-75e1e7b3d538fa1a2396cd36122e0be702931345.zip | |
mktemp: add support for -u
zlib-1.2.6 Makefile uses "mktemp -u".
function old new delta
___path_search - 266 +266
mktemp_main 165 250 +85
tempnam - 79 +79
packed_usage 29189 29176 -13
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 1/1 up/down: 430/-13) Total: 417 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/mktemp.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 007cb1c5b..dbe430955 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | ////usage: "\n -q Fail silently on errors" - we ignore this opt | 41 | ////usage: "\n -q Fail silently on errors" - we ignore this opt |
| 42 | //usage: "\n -t Prepend base directory name to TEMPLATE" | 42 | //usage: "\n -t Prepend base directory name to TEMPLATE" |
| 43 | //usage: "\n -p DIR Use DIR as a base directory (implies -t)" | 43 | //usage: "\n -p DIR Use DIR as a base directory (implies -t)" |
| 44 | //usage: "\n -u Do not create anything; print a name" | ||
| 44 | //usage: "\n" | 45 | //usage: "\n" |
| 45 | //usage: "\nBase directory is: -p DIR, else $TMPDIR, else /tmp" | 46 | //usage: "\nBase directory is: -p DIR, else $TMPDIR, else /tmp" |
| 46 | //usage: | 47 | //usage: |
| @@ -63,6 +64,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 63 | OPT_q = 1 << 1, | 64 | OPT_q = 1 << 1, |
| 64 | OPT_t = 1 << 2, | 65 | OPT_t = 1 << 2, |
| 65 | OPT_p = 1 << 3, | 66 | OPT_p = 1 << 3, |
| 67 | OPT_u = 1 << 4, | ||
| 66 | }; | 68 | }; |
| 67 | 69 | ||
| 68 | path = getenv("TMPDIR"); | 70 | path = getenv("TMPDIR"); |
| @@ -71,7 +73,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 71 | 73 | ||
| 72 | /* -q is ignored */ | 74 | /* -q is ignored */ |
| 73 | opt_complementary = "?1"; /* 1 argument max */ | 75 | opt_complementary = "?1"; /* 1 argument max */ |
| 74 | opts = getopt32(argv, "dqtp:", &path); | 76 | opts = getopt32(argv, "dqtp:u", &path); |
| 75 | 77 | ||
| 76 | chp = argv[optind]; | 78 | chp = argv[optind]; |
| 77 | if (!chp) { | 79 | if (!chp) { |
| @@ -81,6 +83,22 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 81 | chp = xstrdup("tmp.XXXXXX"); | 83 | chp = xstrdup("tmp.XXXXXX"); |
| 82 | opts |= OPT_t; | 84 | opts |= OPT_t; |
| 83 | } | 85 | } |
| 86 | |||
| 87 | if (opts & OPT_u) { | ||
| 88 | /* Remove (up to) 6 X's */ | ||
| 89 | unsigned len = strlen(chp); | ||
| 90 | int cnt = len > 6 ? 6 : len; | ||
| 91 | while (--cnt >= 0 && chp[--len] == 'X') | ||
| 92 | chp[len] = '\0'; | ||
| 93 | |||
| 94 | chp = tempnam(opts & (OPT_t|OPT_p) ? path : "./", chp); | ||
| 95 | if (!chp) | ||
| 96 | return EXIT_FAILURE; | ||
| 97 | if (!(opts & (OPT_t|OPT_p))) | ||
| 98 | chp += 2; | ||
| 99 | goto ret; | ||
| 100 | } | ||
| 101 | |||
| 84 | if (opts & (OPT_t|OPT_p)) | 102 | if (opts & (OPT_t|OPT_p)) |
| 85 | chp = concat_path_file(path, chp); | 103 | chp = concat_path_file(path, chp); |
| 86 | 104 | ||
| @@ -91,8 +109,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 91 | if (mkstemp(chp) < 0) | 109 | if (mkstemp(chp) < 0) |
| 92 | return EXIT_FAILURE; | 110 | return EXIT_FAILURE; |
| 93 | } | 111 | } |
| 94 | 112 | ret: | |
| 95 | puts(chp); | 113 | puts(chp); |
| 96 | |||
| 97 | return EXIT_SUCCESS; | 114 | return EXIT_SUCCESS; |
| 98 | } | 115 | } |
