blob: 4a1960dff255ee862c00cebb24139a2a29b6802c [file] [log] [blame]
Andrew Geissler5f350902021-07-23 13:09:54 -04001From ceb378209f953ea745ed93a8645567196380ce3c Mon Sep 17 00:00:00 2001
2From: Andrej Valek <andrej.valek@siemens.com>
3Date: Thu, 24 Jun 2021 19:13:22 +0200
4Subject: [PATCH] mktemp: add tmpdir option
5
6Make mktemp more compatible with coreutils.
7- add "--tmpdir" option
8- add long variants for "d,q,u" options
9
10Upstream-Status: Submitted [http://lists.busybox.net/pipermail/busybox/2021-June/088932.html]
11
12Signed-off-by: Andrej Valek <andrej.valek@siemens.com>
13Signed-off-by: Peter Marko <peter.marko@siemens.com>
14---
15 coreutils/mktemp.c | 26 ++++++++++++++++++--------
16 1 file changed, 18 insertions(+), 8 deletions(-)
17
18diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c
19index 5393320a5..05c6d98c6 100644
20--- a/coreutils/mktemp.c
21+++ b/coreutils/mktemp.c
22@@ -39,16 +39,17 @@
23 //kbuild:lib-$(CONFIG_MKTEMP) += mktemp.o
24
25 //usage:#define mktemp_trivial_usage
26-//usage: "[-dt] [-p DIR] [TEMPLATE]"
27+//usage: "[-dt] [-p DIR, --tmpdir[=DIR]] [TEMPLATE]"
28 //usage:#define mktemp_full_usage "\n\n"
29 //usage: "Create a temporary file with name based on TEMPLATE and print its name.\n"
30 //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n"
31 //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n"
32-//usage: "\n -d Make directory, not file"
33-//usage: "\n -q Fail silently on errors"
34-//usage: "\n -t Prepend base directory name to TEMPLATE"
35-//usage: "\n -p DIR Use DIR as a base directory (implies -t)"
36-//usage: "\n -u Do not create anything; print a name"
37+//usage: "\n -d Make directory, not file"
38+//usage: "\n -q Fail silently on errors"
39+//usage: "\n -t Prepend base directory name to TEMPLATE"
40+//usage: "\n -p DIR, --tmpdir[=DIR] Use DIR as a base directory (implies -t)"
41+//usage: "\n For --tmpdir is a optional one."
42+//usage: "\n -u Do not create anything; print a name"
43 //usage: "\n"
44 //usage: "\nBase directory is: -p DIR, else $TMPDIR, else /tmp"
45 //usage:
46@@ -72,13 +73,22 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
47 OPT_t = 1 << 2,
48 OPT_p = 1 << 3,
49 OPT_u = 1 << 4,
50+ OPT_td = 1 << 5,
51 };
52
53 path = getenv("TMPDIR");
54 if (!path || path[0] == '\0')
55 path = "/tmp";
56
57- opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
58+ opts = getopt32long(argv, "^"
59+ "dqtp:u\0"
60+ "?1" /* 1 arg max */,
61+ "directory\0" No_argument "d"
62+ "quiet\0" No_argument "q"
63+ "dry-run\0" No_argument "u"
64+ "tmpdir\0" Optional_argument "\xff"
65+ , &path, &path
66+ );
67
68 chp = argv[optind];
69 if (!chp) {
70@@ -95,7 +105,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
71 goto error;
72 }
73 #endif
74- if (opts & (OPT_t|OPT_p))
75+ if (opts & (OPT_t|OPT_p|OPT_td))
76 chp = concat_path_file(path, chp);
77
78 if (opts & OPT_u) {
79--
802.11.0
81