diff options
| author | Ron Yorston <rmy@pobox.com> | 2012-10-10 12:56:24 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2012-10-10 12:56:24 +0100 |
| commit | 981a6fcd1323a77d5829c7d574bb40fd1b96dc4d (patch) | |
| tree | a1e3aadf4de65d7a525c7dd6172546ff577777d5 /debianutils | |
| parent | 19436cc0ee509a5e356c04f0026919abd417bec4 (diff) | |
| parent | eab343e7e1e5331df833aa69f14584e4a6c738f1 (diff) | |
| download | busybox-w32-981a6fcd1323a77d5829c7d574bb40fd1b96dc4d.tar.gz busybox-w32-981a6fcd1323a77d5829c7d574bb40fd1b96dc4d.tar.bz2 busybox-w32-981a6fcd1323a77d5829c7d574bb40fd1b96dc4d.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/mktemp.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index dbe430955..983d7a246 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
| @@ -38,7 +38,7 @@ | |||
| 38 | //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n" | 38 | //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n" |
| 39 | //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n" | 39 | //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n" |
| 40 | //usage: "\n -d Make directory, not file" | 40 | //usage: "\n -d Make directory, not file" |
| 41 | ////usage: "\n -q Fail silently on errors" - we ignore this opt | 41 | //usage: "\n -q Fail silently on errors" |
| 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 -u Do not create anything; print a name" |
| @@ -71,7 +71,6 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 71 | if (!path || path[0] == '\0') | 71 | if (!path || path[0] == '\0') |
| 72 | path = "/tmp"; | 72 | path = "/tmp"; |
| 73 | 73 | ||
| 74 | /* -q is ignored */ | ||
| 75 | opt_complementary = "?1"; /* 1 argument max */ | 74 | opt_complementary = "?1"; /* 1 argument max */ |
| 76 | opts = getopt32(argv, "dqtp:u", &path); | 75 | opts = getopt32(argv, "dqtp:u", &path); |
| 77 | 76 | ||
| @@ -83,33 +82,32 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 83 | chp = xstrdup("tmp.XXXXXX"); | 82 | chp = xstrdup("tmp.XXXXXX"); |
| 84 | opts |= OPT_t; | 83 | opts |= OPT_t; |
| 85 | } | 84 | } |
| 86 | 85 | #if 0 | |
| 87 | if (opts & OPT_u) { | 86 | /* Don't allow directory separator in template */ |
| 88 | /* Remove (up to) 6 X's */ | 87 | if ((opts & OPT_t) && bb_basename(chp) != chp) { |
| 89 | unsigned len = strlen(chp); | 88 | errno = EINVAL; |
| 90 | int cnt = len > 6 ? 6 : len; | 89 | goto error; |
| 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 | } | 90 | } |
| 101 | 91 | #endif | |
| 102 | if (opts & (OPT_t|OPT_p)) | 92 | if (opts & (OPT_t|OPT_p)) |
| 103 | chp = concat_path_file(path, chp); | 93 | chp = concat_path_file(path, chp); |
| 104 | 94 | ||
| 105 | if (opts & OPT_d) { | 95 | if (opts & OPT_u) { |
| 96 | chp = mktemp(chp); | ||
| 97 | if (chp[0] == '\0') | ||
| 98 | goto error; | ||
| 99 | } else if (opts & OPT_d) { | ||
| 106 | if (mkdtemp(chp) == NULL) | 100 | if (mkdtemp(chp) == NULL) |
| 107 | return EXIT_FAILURE; | 101 | goto error; |
| 108 | } else { | 102 | } else { |
| 109 | if (mkstemp(chp) < 0) | 103 | if (mkstemp(chp) < 0) |
| 110 | return EXIT_FAILURE; | 104 | goto error; |
| 111 | } | 105 | } |
| 112 | ret: | ||
| 113 | puts(chp); | 106 | puts(chp); |
| 114 | return EXIT_SUCCESS; | 107 | return EXIT_SUCCESS; |
| 108 | error: | ||
| 109 | if (opts & OPT_q) | ||
| 110 | return EXIT_FAILURE; | ||
| 111 | /* don't use chp as it gets mangled in case of error */ | ||
| 112 | bb_perror_nomsg_and_die(); | ||
| 115 | } | 113 | } |
