Skip to content

Commit

Permalink
Fix mg_time on mbed and make DNS work around epoch
Browse files Browse the repository at this point in the history
PUBLISHED_FROM=c1aeef9dc25baba794b3269b44441c5bafbca5a8
  • Loading branch information
Marko Mikulicic authored and cesantabot committed Oct 20, 2016
1 parent c0c2df0 commit 3d4c9df
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions v7.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,55 @@ int inet_pton(int af, const char *src, void *dst);

/* Amalgamated: #include "mbed.h" */

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <time.h>

#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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 3d4c9df

Please sign in to comment.