diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-11-24 12:09:52 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-09-30 17:34:03 -0400 |
commit | f37847b1f6d52eef66e2a775706e5bdecc00e136 (patch) | |
tree | a686fc77f5614a113ba98bb11c16e0c64c3c4e4d /src/fdevent.c | |
parent | cc2fcd3ece8453ebcf1b302b02e7863ddf1ca88d (diff) | |
download | lighttpd-git-f37847b1f6d52eef66e2a775706e5bdecc00e136.tar.gz |
[core] _WIN32 impl of fdevent_mkostemp()
Diffstat (limited to 'src/fdevent.c')
-rw-r--r-- | src/fdevent.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/fdevent.c b/src/fdevent.c index 276bb365..01fe66e2 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -15,6 +15,12 @@ #include <errno.h> #include <fcntl.h> +#ifdef _WIN32 +#include <sys/stat.h> /* _S_IREAD _S_IWRITE */ +#include <io.h> +#include <share.h> /* _SH_DENYRW */ +#endif + #ifdef SOCK_CLOEXEC static int use_sock_cloexec; #endif @@ -639,7 +645,17 @@ int fdevent_pipe_cloexec (int * const fds, const unsigned int bufsz_hint) { int fdevent_mkostemp(char *path, int flags) { - #if defined(HAVE_MKOSTEMP) + #ifdef _WIN32 + /* future: if _sopen_s() returns EEXIST, might reset template (path) with + * trailing "XXXXXX", and then loop to try again */ + int fd; /*(flags might have _O_APPEND)*/ + return (0 == _mktemp_s(path, strlen(path)+1)) + && (0 == _sopen_s(&fd, path, _O_CREAT | _O_EXCL | _O_TEMPORARY + | flags | _O_BINARY | _O_NOINHERIT, + _SH_DENYRW, _S_IREAD | _S_IWRITE)) + ? fd + : -1; + #elif defined(HAVE_MKOSTEMP) return mkostemp(path, O_CLOEXEC | flags); #else #ifdef __COVERITY__ @@ -660,6 +676,7 @@ int fdevent_mkostemp(char *path, int flags) { fdevent_setfd_cloexec(fd); return fd; + #endif } |