From 1ab46d43bc5753a42f8543234f94f7abc152d228 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 26 Nov 2020 15:10:56 -0500 Subject: [multiple] _WIN32 stat() compat sys-stat.h no lstat() no S_IFSOCK no S_ISSOCK() ... --- src/Makefile.am | 3 +- src/configfile.c | 7 +-- src/gw_backend.c | 2 +- src/http_etag.h | 4 +- src/mod_deflate.c | 6 +- src/mod_dirlisting.c | 3 +- src/mod_rrdtool.c | 2 +- src/mod_webdav.c | 2 +- src/response.c | 2 +- src/server.c | 16 ++++- src/stat_cache.c | 16 ++--- src/stat_cache.h | 2 +- src/sys-stat.h | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 195 insertions(+), 31 deletions(-) create mode 100644 src/sys-stat.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 4483a041..4a3d3042 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -361,7 +361,8 @@ hdr = base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \ rand.h \ sys-crypto.h sys-crypto-md.h \ sys-endian.h sys-mmap.h sys-setjmp.h \ - sys-socket.h sys-strings.h sys-time.h \ + sys-socket.h sys-stat.h sys-strings.h \ + sys-time.h \ sock_addr.h \ mod_auth_api.h \ mod_magnet_cache.h \ diff --git a/src/configfile.c b/src/configfile.c index ec520ea8..897f8276 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -1,5 +1,7 @@ #include "first.h" +#include "sys-stat.h" + #include "base.h" #include "burl.h" #include "chunk.h" @@ -18,11 +20,6 @@ #include "stat_cache.h" #include "sys-crypto.h" -#include -#ifdef HAVE_SYS_WAIT_H -#include -#endif - #include #include #include diff --git a/src/gw_backend.c b/src/gw_backend.c index e2893f6c..2b4f13af 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -9,8 +9,8 @@ #include "gw_backend.h" #include -#include #include "sys-socket.h" +#include "sys-stat.h" #ifdef HAVE_SYS_UIO_H #include #endif diff --git a/src/http_etag.h b/src/http_etag.h index d200bf48..5088607c 100644 --- a/src/http_etag.h +++ b/src/http_etag.h @@ -10,8 +10,8 @@ #include "buffer.h" -#ifdef _AIX -#include +#if defined(_AIX) || defined(_WIN32) +#include "sys-stat.h" #else struct stat; /* declaration */ #endif diff --git a/src/mod_deflate.c b/src/mod_deflate.c index d8322d32..ffceceb2 100644 --- a/src/mod_deflate.c +++ b/src/mod_deflate.c @@ -99,11 +99,11 @@ #include "first.h" #include -#include #include "sys-mmap.h" #ifdef HAVE_MMAP #include "sys-setjmp.h" #endif +#include "sys-stat.h" #include "sys-time.h" #include @@ -293,10 +293,6 @@ FREE_FUNC(mod_deflate_free) { } } -#if defined(_WIN32) && !defined(__CYGWIN__) -#define mkdir(x,y) mkdir(x) -#endif - static int mkdir_for_file (char *fn) { for (char *p = fn; (p = strchr(p + 1, '/')) != NULL; ) { if (p[1] == '\0') return 0; /* ignore trailing slash */ diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index 13816d0a..597cbec0 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -11,6 +11,7 @@ #include "first.h" +#include "sys-stat.h" #include "sys-time.h" #include "base.h" @@ -1548,8 +1549,6 @@ static int mod_dirlisting_write_cq (const int fd, chunkqueue * const cq, log_err } -#include /* mkdir() */ -#include /*(similar to mod_deflate.c:mkdir_recursive(), but starts mid-path)*/ static int mkdir_recursive (char *dir, size_t off) { char *p = dir+off; diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index 91fd76a5..986212e2 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -7,7 +7,7 @@ #include "plugin.h" #include -#include +#include "sys-stat.h" #include "sys-time.h" #include diff --git a/src/mod_webdav.c b/src/mod_webdav.c index 0318f36b..77b6a5dc 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -178,7 +178,7 @@ #include "first.h" /* first */ #include "sys-mmap.h" #include -#include +#include "sys-stat.h" #include "sys-time.h" #include #include diff --git a/src/response.c b/src/response.c index e0ae02d1..f2f0d3dd 100644 --- a/src/response.c +++ b/src/response.c @@ -18,7 +18,7 @@ #include "plugins.h" #include -#include +#include "sys-stat.h" #include "sys-time.h" #include diff --git a/src/server.c b/src/server.c index fe787bb0..f396cc5b 100644 --- a/src/server.c +++ b/src/server.c @@ -30,8 +30,8 @@ static const buffer default_server_tag = { PACKAGE_DESC "\0server", sizeof(PACKAGE_DESC), 0 }; #include -#include #include "sys-setjmp.h" +#include "sys-stat.h" #include "sys-time.h" #include @@ -1264,6 +1264,16 @@ static int server_main_setup (server * const srv, int argc, char **argv) { i_am_root = (0 == getuid()); #endif +#ifdef _WIN32 + /* https://docs.microsoft.com/en-us/cpp/c-runtime-library/fmode?view=msvc-160 */ + /* https://sourceforge.net/p/mingw-w64/bugs/857/ */ + /*_set_fmode(_O_BINARY);*/ + _fmode = _O_BINARY; + (void)_setmode(_fileno(stdin), _O_BINARY); + (void)_setmode(_fileno(stdout), _O_BINARY); + (void)_setmode(_fileno(stderr), _O_BINARY); +#endif + /* initialize globals (including file-scoped static globals) */ oneshot_fd = 0; oneshot_fdout = -1; @@ -1392,6 +1402,7 @@ static int server_main_setup (server * const srv, int argc, char **argv) { return -1; } + #ifndef _WIN32 /*(skip S_ISFIFO() and hope for the best if _WIN32)*/ if (S_ISFIFO(st.st_mode)) { oneshot_fdout = dup(STDOUT_FILENO); if (oneshot_fdout <= STDERR_FILENO) { @@ -1399,6 +1410,8 @@ static int server_main_setup (server * const srv, int argc, char **argv) { return -1; } } + #endif + #ifndef _WIN32 /*(skip S_ISSOCK() and hope for the best if _WIN32)*/ else if (!S_ISSOCK(st.st_mode)) { /* require that fd is a socket * (modules might expect STDIN_FILENO and STDOUT_FILENO opened to /dev/null) */ @@ -1406,6 +1419,7 @@ static int server_main_setup (server * const srv, int argc, char **argv) { "lighttpd -1 stdin is not a socket"); return -1; } + #endif } if (srv->srvconf.bindhost && buffer_is_equal_string(srv->srvconf.bindhost, CONST_STR_LEN("/dev/stdin"))) { diff --git a/src/stat_cache.c b/src/stat_cache.c index 0c639384..f54c1faf 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -1,14 +1,14 @@ #include "first.h" #include "stat_cache.h" + +#include "sys-stat.h" + #include "log.h" #include "fdevent.h" #include "http_etag.h" #include "algo_splaytree.h" -#include -#include - #include #include #include @@ -25,13 +25,6 @@ # include #endif -#ifndef HAVE_LSTAT -#define lstat stat -#ifndef S_ISLNK -#define S_ISLNK(mode) (0) -#endif -#endif - /* * stat-cache * @@ -1452,6 +1445,9 @@ int stat_cache_path_contains_symlink(const buffer *name, log_error_st *errh) { return -1; } } while ((s_cur = strrchr(buf, '/')) > buf); /*(&buf[0]==buf; NULL < buf)*/ + #else + UNUSED(name); + UNUSED(errh); #endif return 0; diff --git a/src/stat_cache.h b/src/stat_cache.h index 18c76b9e..d0a592a5 100644 --- a/src/stat_cache.h +++ b/src/stat_cache.h @@ -2,7 +2,7 @@ #define _FILE_CACHE_H_ #include "first.h" -#include +#include "sys-stat.h" #include "sys-time.h" #include "base_decls.h" diff --git a/src/sys-stat.h b/src/sys-stat.h new file mode 100644 index 00000000..9d282858 --- /dev/null +++ b/src/sys-stat.h @@ -0,0 +1,161 @@ +/* + * sys-stat.h - sys/stat.h wrapper + * + * Copyright(c) 2020 Glenn Strauss gstrauss()gluelogic.com All rights reserved + * License: BSD 3-clause (same as lighttpd) + */ +#ifndef INCLUDED_SYS_STAT_H +#define INCLUDED_SYS_STAT_H +#include "first.h" + +#include +#include + + +#ifdef _WIN32 + +#ifndef S_IRWXU +#define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) +#endif +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif +#ifndef S_IXUSR +#define S_IXUSR _S_IEXEC +#endif + +/* not available on _WIN32 */ +#ifndef S_IRWXG +#define S_IRWXG 0 +#endif +#ifndef S_IRGRP +#define S_IRGRP 0 +#endif +#ifndef S_IWGRP +#define S_IWGRP 0 +#endif +#ifndef S_IXGRP +#define S_IXGRP 0 +#endif + +/* not available on _WIN32 */ +#ifndef S_IRWXO +#define S_IRWXO 0 +#endif +#ifndef S_IROTH +#define S_IROTH 0 +#endif +#ifndef S_IWOTH +#define S_IWOTH 0 +#endif +#ifndef S_IXOTH +#define S_IXOTH 0 +#endif + +/* not available on _WIN32 */ +#ifndef S_ISUID +#define S_ISUID 0 +#endif +#ifndef S_ISGID +#define S_ISGID 0 +#endif +#ifndef S_ISVTX +#define S_ISVTX 0 +#endif + +#ifndef S_IFMT +#define S_IFMT _S_IFMT +#endif +#ifndef S_IFBLK +#define S_IFBLK _S_IFBLK +#endif +#ifndef S_IFCHR +#define S_IFCHR _S_IFCHR +#endif +#ifndef S_IFDIR +#define S_IFDIR _S_IFDIR +#endif +#ifdef _S_IFIFO +#ifndef S_IFIFO +#define S_IFIFO _S_IFIFO +#endif +#endif +#ifndef S_IFREG +#define S_IFREG _S_IFREG +#endif +#ifdef _S_IFLNK +#ifndef S_IFLNK +#define S_IFLNK _S_IFLNK +#endif +#endif +#ifdef _S_IFSOCK +#ifndef S_IFSOCK +#define S_IFSOCK _S_IFSOCK +#endif +#endif + +#ifndef __S_ISTYPE +#define __S_ISTYPE(mode,mask) (((mode) & _S_IFMT) == (mask)) +#endif +#ifndef S_ISBLK +#define S_ISBLK(mode) __S_ISTYPE((mode), _S_IFBLK) +#endif +#ifndef S_ISCHR +#define S_ISCHR(mode) __S_ISTYPE((mode), _S_IFCHR) +#endif +#ifndef S_ISDIR +#define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR) +#endif +#ifdef _S_IFIFO +#ifndef S_ISFIFO +#define S_ISFIFO(mode) __S_ISTYPE((mode), _S_IFIFO) +#endif +#endif +#ifdef _S_IFLNK +#ifndef S_ISLNK +#define S_ISLNK(mode) __S_ISTYPE((mode), _S_IFLNK) +#endif +#endif +#ifndef S_ISREG +#define S_ISREG(mode) __S_ISTYPE((mode), _S_IFREG) +#endif +#ifdef _S_IFSOCK +#ifndef S_ISSOCK +#define S_ISSOCK(mode) __S_ISTYPE((mode), _S_IFSOCK) +#endif +#endif + +/* stat/fstat with 64-bit file length (struct stat, too) */ +#undef stat +#undef fstat +#define stat _stati64 +#define fstat _fstati64 + +#if !defined(__MINGW32__) && !defined(__MINGW64__) +#include +#undef mkdir +#define mkdir(a,b) _mkdir(a) +#endif + +#endif /* _WIN32 */ + + +#ifndef S_ISFIFO +#define S_ISFIFO(mode) 0 +#endif +#ifndef S_ISLNK +#define S_ISLNK(mode) 0 +#endif +#ifndef S_ISSOCK +#define S_ISSOCK(mode) 0 +#endif + +#ifndef HAVE_LSTAT +#define lstat(a,b) stat((a),(b)) +#endif + + +#endif -- cgit v1.2.1