source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Two minor improvements: 1.
Date: Sun, 19 Sep 2021 10:03:25 -0500 (EST)	[thread overview]
Message-ID: <c2aac9643666c062@mandoc.bsd.lv> (raw)

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


                 reply	other threads:[~2021-09-19 15:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2aac9643666c062@mandoc.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    --subject='Re: mandoc: Two minor improvements: 1.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).