From fb0a9bc7e3c43172a58ad47c93033f887ea75271 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 21 Dec 2021 18:16:12 +0000 Subject: [PATCH] Fix build --- Makefile | 2 +- examples/multi-threaded/main.c | 2 +- mongoose.c | 7 +------ mongoose.h | 10 +++++++++- src/arch_unix.h | 3 +++ src/arch_win32.h | 4 +++- src/fs.h | 1 + src/fs_posix.c | 5 +---- src/http.h | 1 + src/util.c | 2 -- src/util.h | 1 + 11 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index a1d8c88b..2f2debce 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SRCS = mongoose.c test/unit_test.c test/packed_fs.c HDRS = $(wildcard src/*.h) DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wmissing-prototypes -Wundef +WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef OPTS ?= -O3 -g3 INCS ?= -Isrc -I. CFLAGS ?= $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) $(EXTRA) diff --git a/examples/multi-threaded/main.c b/examples/multi-threaded/main.c index 433ec1ff..02aa020e 100644 --- a/examples/multi-threaded/main.c +++ b/examples/multi-threaded/main.c @@ -36,7 +36,7 @@ static void start_thread(void (*f)(void *), void *p) { static void thread_function(void *param) { struct mg_connection *c = param; // Pipe connection - mg_usleep(2 * 1000000); // Simulate long execution + sleep(2); // Simulate long execution mg_mgr_wakeup(c); // Wakeup event manager } diff --git a/mongoose.c b/mongoose.c index b5738d64..5848d14d 100644 --- a/mongoose.c +++ b/mongoose.c @@ -700,11 +700,8 @@ static size_t p_seek(void *fp, size_t offset) { #endif return (size_t) ftell((FILE *) fp); } + #else -static char *p_realpath(const char *path, char *resolved_path) { - (void) path, (void) resolved_path; - return NULL; -} static int p_stat(const char *path, size_t *size, time_t *mtime) { (void) path, (void) size, (void) mtime; @@ -4161,8 +4158,6 @@ struct mg_str mg_url_pass(const char *url) { #endif - - #if MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__) #include #endif diff --git a/mongoose.h b/mongoose.h index ea85e1fc..bc551116 100644 --- a/mongoose.h +++ b/mongoose.h @@ -330,7 +330,10 @@ struct timeval { #include #define MG_INT64_FMT "%" PRId64 + +#ifndef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 +#endif #endif @@ -384,6 +387,7 @@ typedef enum { false = 0, true = 1 } bool; // Protect from calls like std::snprintf in app code // See https://github.com/cesanta/mongoose/issues/1047 #ifndef __cplusplus +#define sleep(x) Sleep(x) #define snprintf _snprintf #define vsnprintf _vsnprintf #ifndef strdup // For MSVC with _DEBUG, see #1359 @@ -417,8 +421,9 @@ typedef int socklen_t; #define MG_INT64_FMT "%I64d" -#undef MG_ENABLE_DIRLIST +#ifndef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 +#endif // https://lgtm.com/rules/2154840805/ -gmtime, localtime, ctime and asctime static __inline struct tm *gmtime_r(time_t *t, struct tm *tm) { @@ -598,6 +603,7 @@ void mg_timer_poll(unsigned long current_time_ms); + char *mg_file_read(const char *path, size_t *size); bool mg_file_write(const char *path, const void *buf, size_t len); bool mg_file_printf(const char *path, const char *fmt, ...); @@ -664,6 +670,7 @@ unsigned long mg_millis(void); + enum { MG_FS_READ = 1, MG_FS_WRITE = 2, MG_FS_DIR = 4 }; // Filesystem API functions @@ -860,6 +867,7 @@ void mg_mgr_wakeup(struct mg_connection *pipe); + struct mg_http_header { struct mg_str name; // Header name struct mg_str value; // Header value diff --git a/src/arch_unix.h b/src/arch_unix.h index d74fe2df..4a9e9a3c 100644 --- a/src/arch_unix.h +++ b/src/arch_unix.h @@ -30,6 +30,9 @@ #include #define MG_INT64_FMT "%" PRId64 + +#ifndef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 +#endif #endif diff --git a/src/arch_win32.h b/src/arch_win32.h index a9183227..c56da00d 100644 --- a/src/arch_win32.h +++ b/src/arch_win32.h @@ -49,6 +49,7 @@ typedef enum { false = 0, true = 1 } bool; // Protect from calls like std::snprintf in app code // See https://github.com/cesanta/mongoose/issues/1047 #ifndef __cplusplus +#define sleep(x) Sleep(x) #define snprintf _snprintf #define vsnprintf _vsnprintf #ifndef strdup // For MSVC with _DEBUG, see #1359 @@ -82,8 +83,9 @@ typedef int socklen_t; #define MG_INT64_FMT "%I64d" -#undef MG_ENABLE_DIRLIST +#ifndef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 +#endif // https://lgtm.com/rules/2154840805/ -gmtime, localtime, ctime and asctime static __inline struct tm *gmtime_r(time_t *t, struct tm *tm) { diff --git a/src/fs.h b/src/fs.h index ecd179f5..9e2381b7 100644 --- a/src/fs.h +++ b/src/fs.h @@ -1,6 +1,7 @@ #pragma once #include "arch.h" +#include "config.h" enum { MG_FS_READ = 1, MG_FS_WRITE = 2, MG_FS_DIR = 4 }; diff --git a/src/fs_posix.c b/src/fs_posix.c index fa12c2cd..846d7393 100644 --- a/src/fs_posix.c +++ b/src/fs_posix.c @@ -185,11 +185,8 @@ static size_t p_seek(void *fp, size_t offset) { #endif return (size_t) ftell((FILE *) fp); } + #else -static char *p_realpath(const char *path, char *resolved_path) { - (void) path, (void) resolved_path; - return NULL; -} static int p_stat(const char *path, size_t *size, time_t *mtime) { (void) path, (void) size, (void) mtime; diff --git a/src/http.h b/src/http.h index d65019e1..8b7ecc6c 100644 --- a/src/http.h +++ b/src/http.h @@ -1,5 +1,6 @@ #pragma once +#include "arch.h" #include "config.h" #include "fs.h" #include "net.h" diff --git a/src/util.c b/src/util.c index b0d9fd62..80b433c2 100644 --- a/src/util.c +++ b/src/util.c @@ -1,5 +1,3 @@ -#include "config.h" // Must go first - important for test++ - #include "util.h" #if MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__) diff --git a/src/util.h b/src/util.h index 41394fd4..501abb36 100644 --- a/src/util.h +++ b/src/util.h @@ -1,6 +1,7 @@ #pragma once #include "arch.h" +#include "config.h" #include "str.h" char *mg_file_read(const char *path, size_t *size);