Browse Source

Fix `gettimeofday` to correctly handle a null argument.

`gettimeofday` is defined to do nothing if passed NULL.
pull/296/head wasi-sdk-16
Dan Gohman 2 years ago
parent
commit
30094b6ed0
  1. 8
      libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c

8
libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c

@ -9,8 +9,10 @@
#include <wasi/api.h> #include <wasi/api.h>
int gettimeofday(struct timeval *restrict tp, void *tz) { int gettimeofday(struct timeval *restrict tp, void *tz) {
__wasi_timestamp_t ts = 0; if (tp != NULL) {
(void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); __wasi_timestamp_t ts = 0;
*tp = timestamp_to_timeval(ts); (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
*tp = timestamp_to_timeval(ts);
}
return 0; return 0;
} }

Loading…
Cancel
Save