diff --git a/ChangeLog.md b/ChangeLog.md index 94e0e7c..e75023d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,7 +9,8 @@ All notable changes to the project are documented in this file. ### Changes ### Fixes -- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure +- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure, use + fallback to `mkostemp()` with `O_CLOEXEC` flag set [v2.4.0][] - 2021-03-27 diff --git a/src/tempfile.c b/src/tempfile.c index 0e7032d..5c5f106 100644 --- a/src/tempfile.c +++ b/src/tempfile.c @@ -26,6 +26,7 @@ #include #include /* O_TMPFILE requires -D_GNU_SOURCE */ #include /* fdopen() */ +#include /* mkostemp() */ #include /* umask() */ /** @@ -53,10 +54,14 @@ FILE *tempfile(void) fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR); umask(oldmask); if (-1 == fd) { - if (errno == EOPNOTSUPP) - return tmpfile(); + if (errno == EOPNOTSUPP) { + char nm[15] = _PATH_TMP "XXXXXXXX"; - return NULL; + fd = mkostemp(nm, O_CLOEXEC); + if (-1 == fd) + return NULL; + } else + return NULL; } return fdopen(fd, "w+");