diff --git a/v7.c b/v7.c index 27a74c985..277692fab 100644 --- a/v7.c +++ b/v7.c @@ -838,10 +838,55 @@ int inet_pton(int af, const char *src, void *dst); /* Amalgamated: #include "mbed.h" */ +#include +#include +#include +#include +#include +#include +#include + #ifndef CS_ENABLE_STDIO #define CS_ENABLE_STDIO 1 #endif +/* + * mbed can be compiled with the ARM compiler which + * just doesn't come with a gettimeofday shim + * because it's a BSD API and ARM targets embedded + * non-unix platforms. + */ +#if defined(__ARMCC_VERSION) || defined(__ICCARM__) +#define _TIMEVAL_DEFINED +#define gettimeofday _gettimeofday + +/* copied from GCC on ARM; for some reason useconds are signed */ +typedef long suseconds_t; /* microseconds (signed) */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; + +#endif + +#if MG_NET_IF == MG_NET_IF_SIMPLELINK + +typedef int sock_t; +#define INVALID_SOCKET (-1) + +#define to64(x) strtoll(x, NULL, 10) +#define INT64_FMT PRId64 +#define INT64_X_FMT PRIx64 +#define SIZE_T_FMT "u" + +#define SOMAXCONN 8 + +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); +char *inet_ntoa(struct in_addr in); +int inet_pton(int af, const char *src, void *dst); + +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */ + #endif /* CS_PLATFORM == CS_P_MBED */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_MBED_H_ */ #ifdef V7_MODULE_LINES @@ -11074,6 +11119,22 @@ void cr_context_free(struct cr_ctx *p_ctx) { long timezone; +/* + * The GCC ARM toolchain for implements a weak + * gettimeofday stub that should be implemented + * to hook the OS time source. But mbed OS doesn't do it; + * the mbed doc only talks about C date and time functions: + * + * https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/tasks/Time/ + * + * gettimeof day is a BSD API. + */ +int _gettimeofday(struct timeval *tv, void *tzvp) { + tv->tv_sec = time(NULL); + tv->tv_usec = 0; + return 0; +} + #endif /* CS_PLATFORM == CS_P_MBED */ #ifdef V7_MODULE_LINES #line 1 "v7/builtin/file.c"