diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-05 12:06:00 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-05 12:06:00 +0000 |
| commit | c05b1684a0bc104f7116b67d1dbdbfddceb4aec2 (patch) | |
| tree | 7e49ac853ea04dd6a69f6dc09e480219f3f0375e /debianutils | |
| parent | 66d56c565e48a73309cca55e2d1a2225d9fcc8d9 (diff) | |
| download | busybox-w32-c05b1684a0bc104f7116b67d1dbdbfddceb4aec2.tar.gz busybox-w32-c05b1684a0bc104f7116b67d1dbdbfddceb4aec2.tar.bz2 busybox-w32-c05b1684a0bc104f7116b67d1dbdbfddceb4aec2.zip | |
mktemp: make argument optional (coreutil 6.12 compat)
function old new delta
mktemp_main 157 174 +17
packed_usage 24508 24504 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 17/-4) Total: 13 bytes
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/mktemp.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index b011fc10c..de27d3023 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
| @@ -9,34 +9,53 @@ | |||
| 9 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 9 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | /* Coreutils 6.12 man page says: | ||
| 13 | * mktemp [OPTION]... [TEMPLATE] | ||
| 14 | * Create a temporary file or directory, safely, and print its name. If | ||
| 15 | * TEMPLATE is not specified, use tmp.XXXXXXXXXX. | ||
| 16 | * -d, --directory | ||
| 17 | * create a directory, not a file | ||
| 18 | * -q, --quiet | ||
| 19 | * suppress diagnostics about file/dir-creation failure | ||
| 20 | * -u, --dry-run | ||
| 21 | * do not create anything; merely print a name (unsafe) | ||
| 22 | * --tmpdir[=DIR] | ||
| 23 | * interpret TEMPLATE relative to DIR. If DIR is not specified, | ||
| 24 | * use $TMPDIR if set, else /tmp. With this option, TEMPLATE must | ||
| 25 | * not be an absolute name. Unlike with -t, TEMPLATE may contain | ||
| 26 | * slashes, but even here, mktemp still creates only the final com- | ||
| 27 | * ponent. | ||
| 28 | * -p DIR use DIR as a prefix; implies -t [deprecated] | ||
| 29 | * -t interpret TEMPLATE as a single file name component, relative to | ||
| 30 | * a directory: $TMPDIR, if set; else the directory specified via | ||
| 31 | * -p; else /tmp [deprecated] | ||
| 32 | */ | ||
| 33 | |||
| 34 | |||
| 12 | #include "libbb.h" | 35 | #include "libbb.h" |
| 13 | 36 | ||
| 14 | int mktemp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 37 | int mktemp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 15 | int mktemp_main(int argc ATTRIBUTE_UNUSED, char **argv) | 38 | int mktemp_main(int argc ATTRIBUTE_UNUSED, char **argv) |
| 16 | { | 39 | { |
| 17 | // -d Make a directory instead of a file | ||
| 18 | // -q Fail silently if an error occurs [bbox: ignored] | ||
| 19 | // -t Generate a path rooted in temporary directory | ||
| 20 | // -p DIR Use DIR as a temporary directory (implies -t) | ||
| 21 | const char *path; | 40 | const char *path; |
| 22 | char *chp; | 41 | char *chp; |
| 23 | unsigned flags; | 42 | unsigned opt; |
| 24 | 43 | ||
| 25 | opt_complementary = "=1"; /* exactly one arg */ | 44 | opt_complementary = "?1"; /* 1 argument max */ |
| 26 | flags = getopt32(argv, "dqtp:", &path); | 45 | opt = getopt32(argv, "dqtp:", &path); |
| 27 | chp = argv[optind]; | 46 | chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXXXXXX"); |
| 28 | 47 | ||
| 29 | if (flags & (4|8)) { /* -t and/or -p */ | 48 | if (opt & (4|8)) { /* -t and/or -p */ |
| 30 | const char *dir = getenv("TMPDIR"); | 49 | const char *dir = getenv("TMPDIR"); |
| 31 | if (dir && *dir != '\0') | 50 | if (dir && *dir != '\0') |
| 32 | path = dir; | 51 | path = dir; |
| 33 | else if (!(flags & 8)) /* No -p */ | 52 | else if (!(opt & 8)) /* no -p */ |
| 34 | path = "/tmp/"; | 53 | path = "/tmp/"; |
| 35 | /* else path comes from -p DIR */ | 54 | /* else path comes from -p DIR */ |
| 36 | chp = concat_path_file(path, chp); | 55 | chp = concat_path_file(path, chp); |
| 37 | } | 56 | } |
| 38 | 57 | ||
| 39 | if (flags & 1) { /* -d */ | 58 | if (opt & 1) { /* -d */ |
| 40 | if (mkdtemp(chp) == NULL) | 59 | if (mkdtemp(chp) == NULL) |
| 41 | return EXIT_FAILURE; | 60 | return EXIT_FAILURE; |
| 42 | } else { | 61 | } else { |
