source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Two minor improvements: 1.
@ 2021-09-19 15:03 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2021-09-19 15:03 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mandoc:
        compat_mkdtemp.c

Revision Data
-------------
Index: compat_mkdtemp.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/compat_mkdtemp.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lcompat_mkdtemp.c -Lcompat_mkdtemp.c -u -p -r1.3 -r1.4
--- compat_mkdtemp.c
+++ compat_mkdtemp.c
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*
- * 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;
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-19 15:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 15:03 mandoc: Two minor improvements: 1 schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).