From f72b8c6034341525d9bf83e5e39f8d5d043c6582 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Wed, 13 Oct 2021 13:00:08 -0600 Subject: [PATCH] Fix some undefined macro warnings. Signed-off-by: James Hilliard --- Makefile | 2 +- mongoose.c | 13 +++++++------ src/fs_posix.c | 5 +++-- src/md5.c | 2 +- src/sock.c | 2 +- src/tls.c | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b17030e5..8d6fe019 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 +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/mongoose.c b/mongoose.c index 9411a8a9..15b0ec8c 100644 --- a/mongoose.c +++ b/mongoose.c @@ -693,8 +693,9 @@ static size_t p_write(void *fp, const void *buf, size_t len) { } static size_t p_seek(void *fp, size_t offset) { -#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ - _XOPEN_SOURCE >= 600 +#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \ + (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ + (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) fseeko((FILE *) fp, (off_t) offset, SEEK_SET); #else fseek((FILE *) fp, (long) offset, SEEK_SET); @@ -1870,7 +1871,7 @@ void mg_log_set_callback(void (*fn)(const void *, size_t, void *), void *fnd) { #include -#if MG_ENABLE_MD5 +#if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5 #if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) #define BYTE_ORDER __BYTE_ORDER #ifndef LITTLE_ENDIAN @@ -3150,7 +3151,7 @@ static void setsockopts(struct mg_connection *c) { setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on)); #endif setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)); -#if ESP32 || ESP8266 || defined(__linux__) +#if (defined(ESP32) && ESP32) || (defined(ESP8266) && ESP8266) || defined(__linux__) int idle = 60; setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); #endif @@ -3691,7 +3692,7 @@ void mg_timer_poll(unsigned long now_ms) { #endif #endif -#if MBEDTLS_VERSION_NUMBER >= 0x03000000 +#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000 #define RNG , rng_get, NULL #else #define RNG @@ -3741,7 +3742,7 @@ static void debug_cb(void *c, int lev, const char *s, int n, const char *s2) { (void) lev; } -#if MBEDTLS_VERSION_NUMBER >= 0x03000000 +#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000 static int rng_get(void *p_rng, unsigned char *buf, size_t len) { (void) p_rng; mg_random(buf, len); diff --git a/src/fs_posix.c b/src/fs_posix.c index 5f17c551..d9b6d3ca 100644 --- a/src/fs_posix.c +++ b/src/fs_posix.c @@ -176,8 +176,9 @@ static size_t p_write(void *fp, const void *buf, size_t len) { } static size_t p_seek(void *fp, size_t offset) { -#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ - _XOPEN_SOURCE >= 600 +#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \ + (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ + (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) fseeko((FILE *) fp, (off_t) offset, SEEK_SET); #else fseek((FILE *) fp, (long) offset, SEEK_SET); diff --git a/src/md5.c b/src/md5.c index 4b1e3d17..5d42a913 100644 --- a/src/md5.c +++ b/src/md5.c @@ -1,7 +1,7 @@ #include #include "md5.h" -#if MG_ENABLE_MD5 +#if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5 #if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) #define BYTE_ORDER __BYTE_ORDER #ifndef LITTLE_ENDIAN diff --git a/src/sock.c b/src/sock.c index c59f5167..087ffac5 100644 --- a/src/sock.c +++ b/src/sock.c @@ -304,7 +304,7 @@ static void setsockopts(struct mg_connection *c) { setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on)); #endif setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)); -#if ESP32 || ESP8266 || defined(__linux__) +#if (defined(ESP32) && ESP32) || (defined(ESP8266) && ESP8266) || defined(__linux__) int idle = 60; setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); #endif diff --git a/src/tls.c b/src/tls.c index 9c7d8fac..04c36f6e 100644 --- a/src/tls.c +++ b/src/tls.c @@ -16,7 +16,7 @@ #endif #endif -#if MBEDTLS_VERSION_NUMBER >= 0x03000000 +#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000 #define RNG , rng_get, NULL #else #define RNG @@ -66,7 +66,7 @@ static void debug_cb(void *c, int lev, const char *s, int n, const char *s2) { (void) lev; } -#if MBEDTLS_VERSION_NUMBER >= 0x03000000 +#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000 static int rng_get(void *p_rng, unsigned char *buf, size_t len) { (void) p_rng; mg_random(buf, len);