From cddff2b1b8861cd59a9a02b9bdfa660f14fa79dd Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sat, 24 Jul 2021 11:40:52 +0100 Subject: [PATCH] Cleanup on riscv baremetal build --- mongoose.c | 12 +++++------- src/http.c | 5 +++-- src/log.c | 3 --- src/sntp.c | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/mongoose.c b/mongoose.c index 2c13f6da..f810f418 100644 --- a/mongoose.c +++ b/mongoose.c @@ -966,8 +966,9 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm, "Content-Range: bytes " MG_INT64_FMT "-" MG_INT64_FMT "/" MG_INT64_FMT "\r\n", r1, r1 + cl - 1, (int64_t) st.st_size); -#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ - _XOPEN_SOURCE >= 600 +#if defined(_FILE_OFFSET_BITS) && \ + (_FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ + _XOPEN_SOURCE >= 600) fseeko(fp, (off_t) r1, SEEK_SET); #else fseek(fp, (long) r1, SEEK_SET); @@ -1576,8 +1577,6 @@ void mg_iobuf_free(struct mg_iobuf *io) { -#if MG_ENABLE_MGOS -#else #if MG_ENABLE_LOG static void mg_log_stdout(const void *buf, size_t len, void *userdata) { (void) userdata; @@ -1644,7 +1643,6 @@ void mg_log_set_callback(void (*fn)(const void *, size_t, void *), void *fnd) { s_fn_param = fnd; } #endif -#endif #ifdef MG_ENABLE_LINES #line 1 "src/md5.c" @@ -2544,7 +2542,7 @@ void mg_hmac_sha1(const unsigned char *key, size_t keylen, #define SNTP_INTERVAL_SEC (3600) -#define SNTP_TIME_OFFSET 2208988800 +#define SNTP_TIME_OFFSET 2208988800UL static unsigned long s_sntmp_next; @@ -2560,7 +2558,7 @@ int mg_sntp_parse(const unsigned char *buf, size_t len, struct timeval *tv) { LOG(LL_ERROR, ("%s", "server sent a kiss of death")); } else { uint32_t *data = (uint32_t *) &buf[40]; - tv->tv_sec = mg_ntohl(data[0]) - SNTP_TIME_OFFSET; + tv->tv_sec = (time_t)(mg_ntohl(data[0]) - SNTP_TIME_OFFSET); tv->tv_usec = (suseconds_t) mg_ntohl(data[1]); s_sntmp_next = (unsigned long) (tv->tv_sec + SNTP_INTERVAL_SEC); res = 0; diff --git a/src/http.c b/src/http.c index a6d1586e..4c96927c 100644 --- a/src/http.c +++ b/src/http.c @@ -547,8 +547,9 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm, "Content-Range: bytes " MG_INT64_FMT "-" MG_INT64_FMT "/" MG_INT64_FMT "\r\n", r1, r1 + cl - 1, (int64_t) st.st_size); -#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ - _XOPEN_SOURCE >= 600 +#if defined(_FILE_OFFSET_BITS) && \ + (_FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \ + _XOPEN_SOURCE >= 600) fseeko(fp, (off_t) r1, SEEK_SET); #else fseek(fp, (long) r1, SEEK_SET); diff --git a/src/log.c b/src/log.c index 5b67879e..a4c0d721 100644 --- a/src/log.c +++ b/src/log.c @@ -1,8 +1,6 @@ #include "log.h" #include "util.h" -#if MG_ENABLE_MGOS -#else #if MG_ENABLE_LOG static void mg_log_stdout(const void *buf, size_t len, void *userdata) { (void) userdata; @@ -69,4 +67,3 @@ void mg_log_set_callback(void (*fn)(const void *, size_t, void *), void *fnd) { s_fn_param = fnd; } #endif -#endif diff --git a/src/sntp.c b/src/sntp.c index 5d814c18..677928ee 100644 --- a/src/sntp.c +++ b/src/sntp.c @@ -1,11 +1,11 @@ +#include "sntp.h" #include "arch.h" #include "event.h" #include "log.h" -#include "sntp.h" #include "util.h" #define SNTP_INTERVAL_SEC (3600) -#define SNTP_TIME_OFFSET 2208988800 +#define SNTP_TIME_OFFSET 2208988800UL static unsigned long s_sntmp_next; @@ -21,7 +21,7 @@ int mg_sntp_parse(const unsigned char *buf, size_t len, struct timeval *tv) { LOG(LL_ERROR, ("%s", "server sent a kiss of death")); } else { uint32_t *data = (uint32_t *) &buf[40]; - tv->tv_sec = mg_ntohl(data[0]) - SNTP_TIME_OFFSET; + tv->tv_sec = (time_t)(mg_ntohl(data[0]) - SNTP_TIME_OFFSET); tv->tv_usec = (suseconds_t) mg_ntohl(data[1]); s_sntmp_next = (unsigned long) (tv->tv_sec + SNTP_INTERVAL_SEC); res = 0;