summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-04-09 23:55:43 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2023-05-03 23:11:34 -0400
commit2695a8b2e21ab7c4c16b7dddb6fff53a4797b98c (patch)
tree90605c43039fc0d6bbe318c6f545868b3db3b0b9 /src
parentd7bbd70bd10e429c18df273dd060006a69a91d1e (diff)
downloadlighttpd-git-2695a8b2e21ab7c4c16b7dddb6fff53a4797b98c.tar.gz
[core] _WIN32 sys-unistd.h to wrap <unistd.h>
(selective implementations; not complete)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/chunk.c2
-rw-r--r--src/configfile.c2
-rw-r--r--src/connections.c2
-rw-r--r--src/fdevent.c2
-rw-r--r--src/fdevent_impl.c2
-rw-r--r--src/fdlog.c2
-rw-r--r--src/fdlog_maint.c2
-rw-r--r--src/gw_backend.c2
-rw-r--r--src/http-header-glue.c2
-rw-r--r--src/http_chunk.c5
-rw-r--r--src/log.c2
-rw-r--r--src/mod_accesslog.c2
-rw-r--r--src/mod_authn_file.c2
-rw-r--r--src/mod_authn_gssapi.c2
-rw-r--r--src/mod_cgi.c5
-rw-r--r--src/mod_deflate.c2
-rw-r--r--src/mod_dirlisting.c2
-rw-r--r--src/mod_rrdtool.c2
-rw-r--r--src/mod_ssi.c2
-rw-r--r--src/mod_webdav.c3
-rw-r--r--src/network.c2
-rw-r--r--src/network_write.c2
-rw-r--r--src/rand.c2
-rw-r--r--src/server.c2
-rw-r--r--src/stat_cache.c2
-rw-r--r--src/sys-unistd.h89
-rw-r--r--src/t/test_mod_indexfile.c10
-rw-r--r--src/t/test_mod_ssi.c2
-rw-r--r--src/t/test_mod_staticfile.c10
30 files changed, 125 insertions, 45 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 628ffc48..6c4fbfc1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -362,7 +362,7 @@ hdr = base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
sys-crypto.h sys-crypto-md.h sys-dirent.h \
sys-endian.h sys-mmap.h sys-setjmp.h \
sys-socket.h sys-stat.h sys-strings.h \
- sys-time.h \
+ sys-time.h sys-unistd.h \
sock_addr.h \
mod_auth_api.h \
mod_magnet_cache.h \
diff --git a/src/chunk.c b/src/chunk.c
index 25c7e9b1..37ca9e5e 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -14,10 +14,10 @@
#include <sys/stat.h>
#include "sys-mmap.h"
#include "sys-setjmp.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <stdlib.h>
#include <fcntl.h>
-#include <unistd.h>
#include <errno.h>
#include <string.h>
diff --git a/src/configfile.c b/src/configfile.c
index 329efe30..020b0eb8 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -1,6 +1,7 @@
#include "first.h"
#include "sys-stat.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include "base.h"
#include "burl.h"
@@ -22,7 +23,6 @@
#include <stdlib.h>
#include <fcntl.h>
-#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
diff --git a/src/connections.c b/src/connections.c
index 102e4afc..cfc2cb19 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -21,9 +21,9 @@
#include "sock_addr_cache.h"
#include <sys/stat.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include <stdlib.h>
-#include <unistd.h>
#include <errno.h>
#include <string.h>
diff --git a/src/fdevent.c b/src/fdevent.c
index ec1e74bb..b2ddd22b 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -4,8 +4,8 @@
#include <sys/types.h>
#include "sys-socket.h"
+#include "sys-unistd.h" /* <unistd.h> */
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
diff --git a/src/fdevent_impl.c b/src/fdevent_impl.c
index d7a71e2f..0b1399f9 100644
--- a/src/fdevent_impl.c
+++ b/src/fdevent_impl.c
@@ -6,7 +6,7 @@
#include "log.h"
#include <sys/types.h>
-#include <unistd.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/fdlog.c b/src/fdlog.c
index 606504bd..82114579 100644
--- a/src/fdlog.c
+++ b/src/fdlog.c
@@ -2,7 +2,7 @@
#include "fdlog.h"
#include <stdlib.h>
-#include <unistd.h> /* close() STDERR_FILENO */
+#include "sys-unistd.h" /* <unistd.h> close() STDERR_FILENO */
#include "ck.h"
diff --git a/src/fdlog_maint.c b/src/fdlog_maint.c
index 0865cf0e..13bfd1dc 100644
--- a/src/fdlog_maint.c
+++ b/src/fdlog_maint.c
@@ -7,7 +7,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include "fdevent.h"
#include "ck.h"
diff --git a/src/gw_backend.c b/src/gw_backend.c
index c5b0ddda..1038da92 100644
--- a/src/gw_backend.c
+++ b/src/gw_backend.c
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include "sys-socket.h"
#include "sys-stat.h"
+#include "sys-unistd.h" /* <unistd.h> */
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
@@ -25,7 +26,6 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
-#include <unistd.h>
#ifndef SIGKILL
#define SIGKILL 9
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index 0473d0d1..4c2b0c0d 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -22,7 +22,7 @@
#include <errno.h>
#include "sys-socket.h"
-#include <unistd.h>
+#include "sys-unistd.h" /* <unistd.h> */
/**
* max size of the HTTP response header from backends
diff --git a/src/http_chunk.c b/src/http_chunk.c
index 4dd59fee..07bfaad9 100644
--- a/src/http_chunk.c
+++ b/src/http_chunk.c
@@ -16,11 +16,10 @@
#include <sys/types.h>
#include <sys/stat.h>
-
-#include <stdlib.h>
-#include <unistd.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
__attribute_noinline__
diff --git a/src/log.c b/src/log.c
index b199b98b..d12d8eb5 100644
--- a/src/log.c
+++ b/src/log.c
@@ -9,12 +9,12 @@
#include <sys/types.h>
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> /* vsnprintf() */
#include <stdlib.h> /* malloc() free() */
-#include <unistd.h>
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c
index 77b69b4b..ced8db66 100644
--- a/src/mod_accesslog.c
+++ b/src/mod_accesslog.c
@@ -15,11 +15,11 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
-#include <unistd.h>
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
diff --git a/src/mod_authn_file.c b/src/mod_authn_file.c
index 5c06e019..ffedcc25 100644
--- a/src/mod_authn_file.c
+++ b/src/mod_authn_file.c
@@ -19,11 +19,13 @@
#include <unistd.h>
#endif
+#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "mod_auth_api.h"
#include "sys-crypto-md.h" /* USE_LIB_CRYPTO */
+#include "sys-unistd.h" /* <unistd.h> */
#include "base64.h"
#include "ck.h"
diff --git a/src/mod_authn_gssapi.c b/src/mod_authn_gssapi.c
index 17a0f98a..78e30437 100644
--- a/src/mod_authn_gssapi.c
+++ b/src/mod_authn_gssapi.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
+#include "sys-unistd.h" /* <unistd.h> */
#include <krb5.h>
#include <gssapi.h>
diff --git a/src/mod_cgi.c b/src/mod_cgi.c
index 17561231..1847da6e 100644
--- a/src/mod_cgi.c
+++ b/src/mod_cgi.c
@@ -14,11 +14,8 @@
#include <sys/types.h>
#include "sys-socket.h"
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
+#include "sys-unistd.h" /* <unistd.h> */
-#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/mod_deflate.c b/src/mod_deflate.c
index ffceceb2..484036c8 100644
--- a/src/mod_deflate.c
+++ b/src/mod_deflate.c
@@ -105,12 +105,12 @@
#endif
#include "sys-stat.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> getpid() read() unlink() write() */
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <unistd.h> /* getpid() read() unlink() write() */
#include "base.h"
#include "ck.h"
diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c
index 8e97acf3..2e920656 100644
--- a/src/mod_dirlisting.c
+++ b/src/mod_dirlisting.c
@@ -14,6 +14,7 @@
#include "sys-dirent.h"
#include "sys-stat.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include "base.h"
#include "log.h"
@@ -33,7 +34,6 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
-#include <unistd.h>
#ifdef AT_FDCWD
#ifndef _ATFILE_SOURCE
diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c
index 986212e2..0e3d4c0e 100644
--- a/src/mod_rrdtool.c
+++ b/src/mod_rrdtool.c
@@ -9,11 +9,11 @@
#include <sys/types.h>
#include "sys-stat.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <errno.h>
typedef struct {
diff --git a/src/mod_ssi.c b/src/mod_ssi.c
index addb4475..aa4c5d87 100644
--- a/src/mod_ssi.c
+++ b/src/mod_ssi.c
@@ -19,6 +19,7 @@
#include "sys-socket.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <sys/types.h>
#include <sys/stat.h>
@@ -31,7 +32,6 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#ifdef HAVE_PWD_H
# include <pwd.h>
diff --git a/src/mod_webdav.c b/src/mod_webdav.c
index 095c2e7d..bc6e2590 100644
--- a/src/mod_webdav.c
+++ b/src/mod_webdav.c
@@ -176,17 +176,18 @@
#endif
#include "first.h" /* first */
+#include <sys/types.h>
#include "sys-dirent.h"
#include "sys-mmap.h"
#include <sys/types.h>
#include "sys-stat.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> getpid() linkat() rmdir() unlinkat() */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h> /* rename() */
#include <stdlib.h> /* strtol() */
#include <string.h>
-#include <unistd.h> /* getpid() linkat() rmdir() unlinkat() */
#ifdef RENAME_NOREPLACE /*(renameat2() not well-supported yet)*/
#ifndef __ANDROID_API__ /*(not yet Android?)*/
diff --git a/src/network.c b/src/network.c
index 8c1d302b..6f1def5e 100644
--- a/src/network.c
+++ b/src/network.c
@@ -14,10 +14,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <string.h>
#include <stdlib.h>
diff --git a/src/network_write.c b/src/network_write.c
index 71efb3b2..5c908c46 100644
--- a/src/network_write.c
+++ b/src/network_write.c
@@ -8,10 +8,10 @@
#include <sys/types.h>
#include "sys-socket.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
#include <string.h>
-#include <unistd.h>
/* on linux 2.4.x you get either sendfile or LFS */
diff --git a/src/rand.c b/src/rand.c
index 68d4224d..b45fd889 100644
--- a/src/rand.c
+++ b/src/rand.c
@@ -13,11 +13,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include "sys-crypto-md.h" /* USE_LIB_CRYPTO and additional crypto lib config */
#ifdef USE_NETTLE_CRYPTO
diff --git a/src/server.c b/src/server.c
index d6a37cbc..9c77dc5c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -33,11 +33,11 @@ static const buffer default_server_tag =
#include "sys-setjmp.h"
#include "sys-stat.h"
#include "sys-time.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <locale.h>
diff --git a/src/stat_cache.c b/src/stat_cache.c
index f54c1faf..9db1d210 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -3,6 +3,7 @@
#include "stat_cache.h"
#include "sys-stat.h"
+#include "sys-unistd.h" /* <unistd.h> */
#include "log.h"
#include "fdevent.h"
@@ -12,7 +13,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <unistd.h>
#include <fcntl.h>
#if defined(HAVE_SYS_XATTR_H)
diff --git a/src/sys-unistd.h b/src/sys-unistd.h
new file mode 100644
index 00000000..81597912
--- /dev/null
+++ b/src/sys-unistd.h
@@ -0,0 +1,89 @@
+/*
+ * sys-unistd.h - unistd.h wrapper (selective; incomplete)
+ *
+ * Copyright(c) 2021 Glenn Strauss gstrauss()gluelogic.com All rights reserved
+ * License: BSD 3-clause (same as lighttpd)
+ */
+#ifndef INCLUDED_SYS_UNISTD_H
+#define INCLUDED_SYS_UNISTD_H
+#include "first.h"
+
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+
+#ifdef _WIN32
+
+
+#include <direct.h>
+
+#undef chdir
+#define chdir(path) _chdir(path)
+
+#undef getcwd
+#define getcwd(buf,sz) _getcwd((buf),(int)(sz))
+
+#if 0 /* mkdir() is from <sys/stat.h> for mode; see local sys-stat.h */
+#undef mkdir
+#define mkdir(a,b) _mkdir(a)
+#endif
+
+#undef rmdir
+#define rmdir(path) _rmdir(path)
+
+
+#include <process.h>
+
+#undef getpid
+#define getpid() _getpid()
+
+
+#include <io.h>
+
+#undef close
+#define close(fd) _close(fd)
+
+/* _dup2() returns 0 on success, not newfd */
+#undef dup2
+#define dup2(oldfd,newfd) (0 == _dup2((oldfd),(newfd)) ? (newfd) : -1)
+
+#undef ftruncate
+#define ftruncate(fd, sz) (!(errno = _chsize_s((fd),(sz))) ? 0 : -1)
+
+#undef lseek
+#define lseek(fd,offset,origin) _lseeki64((fd), (__int64)(offset), (origin))
+
+/* note: read() and write() are not for SOCKET (see winsock2.h) */
+#undef read
+#define read(fd,buffer,buffer_size) _read((fd),(buffer),(unsigned)(buffer_size))
+
+/* note: read() and write() are not for SOCKET (see winsock2.h) */
+#undef write
+#define write(fd,buffer,count) _write((fd),(buffer),(unsigned)(count))
+
+#undef unlink
+#define unlink(path) _unlink(path)
+
+/*#include <stdio.h>*//*(defined in <stdio.h> in _WIN32 ucrt includes)*/
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+
+
+#endif /* _WIN32 */
+
+
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+
+
+#endif
diff --git a/src/t/test_mod_indexfile.c b/src/t/test_mod_indexfile.c
index 616fd280..f316916f 100644
--- a/src/t/test_mod_indexfile.c
+++ b/src/t/test_mod_indexfile.c
@@ -34,18 +34,14 @@ run_mod_indexfile_tryfiles (request_st * const r, const array * const indexfiles
}
}
-#include <unistd.h> /* unlink() */
+#include "sys-unistd.h" /* unlink() */
+#include "fdevent.h"
static void
test_mod_indexfile_tryfiles (request_st * const r)
{
char fn[] = "/tmp/lighttpd_mod_indexfile.XXXXXX";
- #ifdef __COVERITY__
- /* POSIX-2008 requires mkstemp create file with 0600 perms */
- umask(0600);
- #endif
- /* coverity[secure_temp : FALSE] */
- int fd = mkstemp(fn);
+ int fd = fdevent_mkostemp(fn, 0);
if (fd < 0) {
perror("mkstemp()");
exit(1);
diff --git a/src/t/test_mod_ssi.c b/src/t/test_mod_ssi.c
index 2f2a5c49..085d041d 100644
--- a/src/t/test_mod_ssi.c
+++ b/src/t/test_mod_ssi.c
@@ -5,7 +5,7 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
+#include "sys-unistd.h" /* unlink() */
#include "mod_ssi.c"
#include "fdlog.h"
diff --git a/src/t/test_mod_staticfile.c b/src/t/test_mod_staticfile.c
index 6fb260d5..1b95179f 100644
--- a/src/t/test_mod_staticfile.c
+++ b/src/t/test_mod_staticfile.c
@@ -365,18 +365,14 @@ test_mod_staticfile_process (request_st * const r, plugin_config * const pconf)
array_free(a);
}
-#include <unistd.h> /* unlink() */
+#include "sys-unistd.h" /* unlink() */
+#include "fdevent.h"
void test_mod_staticfile (void);
void test_mod_staticfile (void)
{
char fn[] = "/tmp/lighttpd_mod_staticfile.XXXXXX";
- #ifdef __COVERITY__
- /* POSIX-2008 requires mkstemp create file with 0600 perms */
- umask(0600);
- #endif
- /* coverity[secure_temp : FALSE] */
- int fd = mkstemp(fn);
+ int fd = fdevent_mkostemp(fn, 0);
if (fd < 0) {
perror("mkstemp()");
exit(1);