summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/mkhtemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/mkhtemp.c')
-rw-r--r--util/libreboot-utils/mkhtemp.c58
1 files changed, 20 insertions, 38 deletions
diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c
index 61260b49..261227cb 100644
--- a/util/libreboot-utils/mkhtemp.c
+++ b/util/libreboot-utils/mkhtemp.c
@@ -94,7 +94,15 @@ main(int argc, char *argv[])
int stfu = 0; /* -q option */
if (lbgetprogname(argv[0]) == NULL)
- err_mkhtemp(0, errno, "could not set progname");
+ err_no_cleanup(stfu, errno, "could not set progname");
+
+/* https://man.openbsd.org/pledge.2 */
+#if defined(__OpenBSD__) && defined(OpenBSD)
+#if (OpenBSD) >= 509
+ if (pledge("stdio flock rpath wpath cpath", NULL) == -1)
+ goto err_usage;
+#endif
+#endif
while ((c =
getopt(argc, argv, "qdp:")) != -1) {
@@ -118,14 +126,6 @@ main(int argc, char *argv[])
}
}
-/* https://man.openbsd.org/pledge.2 */
-#if defined(__OpenBSD__) && defined(OpenBSD)
-#if (OpenBSD) >= 509
- if (pledge("stdio flock rpath wpath cpath", NULL) == -1)
- goto err_usage;
-#endif
-#endif
-
if (optind < argc)
template = argv[optind];
if (optind + 1 < argc)
@@ -134,15 +134,15 @@ main(int argc, char *argv[])
/* custom template e.g. foo.XXXXXXXXXXXXXXXXXXXXX */
if (template != NULL) {
if (slen(template, maxlen, &tlen) < 0)
- err_mkhtemp(stfu, EINVAL,
+ err_no_cleanup(stfu, EINVAL,
"invalid template");
for (p = template + tlen;
p > template && *--p == 'X'; xc++);
- if (xc < 6)
- err_mkhtemp(stfu, EINVAL,
- "template must end in at least 6 X");
+ if (xc < 3) /* the gnu mktemp errs on less than 3 */
+ err_no_cleanup(stfu, EINVAL,
+ "template must have 3 X or more on end (12+ advised");
}
/* user supplied -p PATH - WARNING:
@@ -155,35 +155,35 @@ main(int argc, char *argv[])
if (tmpdir != NULL) {
rp = realpath(tmpdir, resolved);
if (rp == NULL)
- err_mkhtemp(stfu, errno, "%s", tmpdir);
+ err_no_cleanup(stfu, errno, "%s", tmpdir);
tmpdir = resolved;
}
if (new_tmp_common(&fd, &s, type,
tmpdir, template) < 0)
- err_mkhtemp(stfu, errno, "%s", s);
+ err_no_cleanup(stfu, errno, "%s", s);
#if defined(__OpenBSD__) && defined(OpenBSD)
#if (OpenBSD) >= 509
if (pledge("stdio", NULL) == -1)
- err_mkhtemp(errno, "pledge, exit");
+ err_no_cleanup(stfu, errno, "pledge, exit");
#endif
#endif
if (s == NULL)
- err_mkhtemp(stfu, EFAULT, "bad string initialisation");
+ err_no_cleanup(stfu, EFAULT, "bad string initialisation");
if (*s == '\0')
- err_mkhtemp(stfu, EFAULT, "empty string initialisation");
+ err_no_cleanup(stfu, EFAULT, "empty string initialisation");
if (slen(s, maxlen, &len) < 0)
- err_mkhtemp(stfu, EFAULT, "unterminated string initialisiert");
+ err_no_cleanup(stfu, EFAULT, "unterminated string initialisiert");
printf("%s\n", s);
return EXIT_SUCCESS;
err_usage:
- err_mkhtemp(stfu, EINVAL,
+ err_no_cleanup(stfu, EINVAL,
"usage: %s [-d] [-p dir] [template]\n", getnvmprogname());
}/*
@@ -198,24 +198,6 @@ err_usage:
*/
-void
-err_mkhtemp(int stfu,
- int errval, const char *msg, ...)
-{
- va_list args;
-
- if (stfu || msg == NULL)
- goto out;
-
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
-
- err_no_cleanup(errval, msg, args);
-out:
- exit(EXIT_FAILURE);
-}
-