summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Goncharov <dgoncharov@users.sf.net>2022-10-23 15:45:42 -0400
committerPaul Smith <psmith@gnu.org>2022-10-23 18:41:50 -0400
commit252c26bd2086f80d4ef75f57ee5825dee2f60d83 (patch)
tree89879f4873799c4028869cea0d3bc0d1c8ec8b88
parent6f8da5f4b86a679143d6f6b99e8cfcc1f19a0593 (diff)
downloadmake-git-252c26bd2086f80d4ef75f57ee5825dee2f60d83.tar.gz
* src/posixos.c (os_anontmp): If O_TMPFILE fails try dup() method.
-rw-r--r--src/posixos.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/posixos.c b/src/posixos.c
index fca31927..48e8cf5c 100644
--- a/src/posixos.c
+++ b/src/posixos.c
@@ -839,17 +839,22 @@ fd_set_append (int fd)
int
os_anontmp ()
{
+ const char *tdir = get_tmpdir ();
int fd = -1;
#ifdef O_TMPFILE
- EINTRLOOP (fd, open (get_tmpdir (), O_RDWR | O_TMPFILE | O_EXCL, 0600));
- if (fd < 0)
- pfatal_with_name ("open(O_TMPFILE)");
-#elif HAVE_DUP
- /* We don't have O_TMPFILE but we can dup: if we are creating temp files in
- the default location then try tmpfile() + dup() + fclose() to avoid ever
- having a name for a file. */
- if (streq (get_tmpdir (), DEFAULT_TMPDIR))
+ EINTRLOOP (fd, open (tdir, O_RDWR | O_TMPFILE | O_EXCL, 0600));
+ if (fd >= 0)
+ return fd;
+
+ DB (DB_BASIC, (_("Cannot open '%s' with O_TMPFILE: %s.\n"),
+ tdir, strerror (errno)));
+#endif
+
+#if HAVE_DUP
+ /* If we can dup and we are creating temp files in the default location then
+ try tmpfile() + dup() + fclose() to avoid ever having a named file. */
+ if (streq (tdir, DEFAULT_TMPDIR))
{
mode_t mask = umask (0077);
FILE *tfile;