summaryrefslogtreecommitdiff
path: root/util/libreboot-utils
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-24 20:06:09 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-24 20:14:47 +0000
commit75f03ea696c20af56f20e2327c9c692683c6810a (patch)
treef191f3a84f2515a95278155bda81e74cf3ab6b4d /util/libreboot-utils
parent88ff5f7380c3382092217442dcc962fdca59be3a (diff)
util/mkhtemp: add directory override (-p) option.
-p dir to override TMPDIR Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils')
-rw-r--r--util/libreboot-utils/mkhtemp.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c
index c289c5b4..1f7c8b79 100644
--- a/util/libreboot-utils/mkhtemp.c
+++ b/util/libreboot-utils/mkhtemp.c
@@ -67,6 +67,11 @@
int
main(int argc, char *argv[])
{
+ const char usage_str[] = "usage: %s [-d] [-p dir] [template]";
+
+ char *tmpdir = NULL;
+ char *template = NULL;
+
char *s = NULL;
int fd = -1;
char c;
@@ -87,26 +92,34 @@ main(int argc, char *argv[])
#if defined(__OpenBSD__) && defined(OpenBSD)
#if (OpenBSD) >= 509
if (pledge("stdio flock rpath wpath cpath", NULL) == -1)
- err_no_cleanup(errno, "pledge, main");
+ goto err_usage;
#endif
#endif
- while ((c =
- getopt(argc, argv, "d")) != -1) {
+ while ((c =
+ getopt(argc, argv, "dp:")) != -1) {
- switch(c) {
+ switch (c) {
case 'd':
-
type = MKHTEMP_DIR;
break;
- default:
- err_no_cleanup(EINVAL,
- "usage: mkhtemp [-d]\n");
+ case 'p':
+ tmpdir = optarg;
+ break;
+
+ default:
+ goto err_usage;
}
}
- if (new_tmp_common(&fd, &s, type, NULL) < 0)
+ if (optind < argc)
+ template = argv[optind];
+ if (optind + 1 < argc)
+ err_no_cleanup(EINVAL,
+ "usage: mkhtemp [-d] [-p dir] [template]\n");
+
+ if (new_tmp_common(&fd, &s, type, tmpdir) < 0)
err_no_cleanup(errno, "%s", s);
#if defined(__OpenBSD__) && defined(OpenBSD)
@@ -128,6 +141,10 @@ main(int argc, char *argv[])
printf("%s\n", s);
return EXIT_SUCCESS;
+
+err_usage:
+ err_no_cleanup(EINVAL,
+ "usage: %s [-d] [-p dir] [template]\n", getnvmprogname());
}/*