aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2021-09-19 15:02:55 +0000
committerIngo Schwarze <schwarze@openbsd.org>2021-09-19 15:02:55 +0000
commitda18dde44e7ed710106dba929c6d3e23d85e4666 (patch)
treeb4918253826d7dac0268e03250e4df170a160681
parentafc23456a702c165e1732d36f0c82c283686770e (diff)
downloadmandoc-da18dde44e7ed710106dba929c6d3e23d85e4666.tar.gz
mandoc-da18dde44e7ed710106dba929c6d3e23d85e4666.tar.zst
mandoc-da18dde44e7ed710106dba929c6d3e23d85e4666.zip
Two minor improvements:
1. If mktemp(3) fails, do not overwrite the errno because all errors mktemp(3) might return are also valid for mkdtemp(3). 2. If mkdir(2) fails, always put back the Xes, even if the error is fatal and the function is about to return NULL.
-rw-r--r--compat_mkdtemp.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/compat_mkdtemp.c b/compat_mkdtemp.c
index 296bfd42..c2edfcb1 100644
--- a/compat_mkdtemp.c
+++ b/compat_mkdtemp.c
@@ -1,6 +1,6 @@
-/* $Id: compat_mkdtemp.c,v 1.3 2020/06/15 01:37:15 schwarze Exp $ */
+/* $Id: compat_mkdtemp.c,v 1.4 2021/09/19 15:02:55 schwarze Exp $ */
/*
- * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2015, 2021 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -36,16 +36,14 @@ mkdtemp(char *path)
start--;
for (tries = INT_MAX; tries; tries--) {
- if (mktemp(path) == NULL) {
- errno = EEXIST;
+ if (mktemp(path) == NULL)
return NULL;
- }
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0)
return path;
- if (errno != EEXIST)
- return NULL;
for (cp = start; *cp != '\0'; cp++)
*cp = 'X';
+ if (errno != EEXIST)
+ return NULL;
}
errno = EEXIST;
return NULL;