From e3bac87016c7f7df89ca64d56c29c6607c7c0faf Mon Sep 17 00:00:00 2001 From: Dmitry Frank <dmitry.frank@cesanta.com> Date: Tue, 25 Oct 2016 12:25:37 +0300 Subject: [PATCH] Make mongoose compile with ARMCC (It compiles, but doesn't really work yet) PUBLISHED_FROM=0382d355a343bdab9c9eeed87229efe90c30c40b --- mongoose.c | 32 +++++++++++++++++++++++++++++++- mongoose.h | 16 +++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 0ad41538a..9edc710bb 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1722,6 +1722,20 @@ const char *c_strnstr(const char *s, const char *find, size_t slen) { return NULL; } +/* + * ARM C Compiler doesn't have strdup, so we provide it + */ +#if defined(__ARMCC_VERSION) +char *strdup(const char *src) { + size_t len = strlen(src) + 1; + char *ret = malloc(len); + if (ret != NULL) { + strcpy(ret, src); + } + return ret; +} +#endif + #endif /* EXCLUDE_COMMON */ #ifdef MG_MODULE_LINES #line 1 "mongoose/src/net.c" @@ -10012,6 +10026,22 @@ int gettimeofday(struct timeval *tp, void *tzp) { #endif /* CS_PLATFORM == CS_P_MSP432 */ #ifdef MG_MODULE_LINES +#line 1 "common/platforms/nrf5/nrf5_libc.c" +#endif +/* + * Copyright (c) 2014-2016 Cesanta Software Limited + * All rights reserved + */ + +#if CS_PLATFORM == CS_P_NRF52 && defined(__ARMCC_VERSION) +int gettimeofday(struct timeval *tp, void *tzp) { + /* TODO */ + tp->tv_sec = 0; + tp->tv_usec = 0; + return 0; +} +#endif +#ifdef MG_MODULE_LINES #line 1 "common/platforms/simplelink/sl_fs_slfs.h" #endif /* @@ -11348,7 +11378,7 @@ void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr); # define TCP_NEW tcp_new_ip6 # define TCP_BIND tcp_bind_ip6 # define UDP_BIND udp_bind_ip6 -# define IPADDR_NTOA ip6addr_ntoa +# define IPADDR_NTOA(x) ip6addr_ntoa((const ip6_addr_t *)(x)) # define SET_ADDR(dst, src) \ memcpy((dst)->sin6.sin6_addr.s6_addr, (src)->ip6.addr, \ sizeof((dst)->sin6.sin6_addr.s6_addr)) diff --git a/mongoose.h b/mongoose.h index ae34e7810..a6d1aa542 100644 --- a/mongoose.h +++ b/mongoose.h @@ -850,11 +850,18 @@ int inet_pton(int af, const char *src, void *dst); #define to64(x) strtoll(x, NULL, 10) #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL -#define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_PROVIDE_ERRNO 1 #define MG_LWIP 1 #define MG_ENABLE_IPV6 1 +/* + * For ARM C Compiler, make lwip to export `struct timeval`; for other + * compilers, suppress it. + */ +#if !defined(__ARMCC_VERSION) +# define LWIP_TIMEVAL_PRIVATE 0 +#endif + #define INT64_FMT PRId64 #define SIZE_T_FMT "u" @@ -1566,6 +1573,13 @@ int c_vsnprintf(char *buf, size_t buf_size, const char *format, va_list ap); */ const char *c_strnstr(const char *s, const char *find, size_t slen); +/* + * ARM C Compiler doesn't have strdup, so we provide it + */ +#if defined(__ARMCC_VERSION) +char *strdup(const char *src); +#endif + #ifdef __cplusplus } #endif -- GitLab