diff --git a/libs/libc/include/bits/macros.h b/libs/libc/include/bits/macros.h index ee84c4a3..12ca8372 100644 --- a/libs/libc/include/bits/macros.h +++ b/libs/libc/include/bits/macros.h @@ -7,5 +7,6 @@ #define __lc_is_deprecated __attribute__((deprecated)) #define __lc_unreachable __builtin_unreachable #define __lc_used __attribute__((used)) +#define __lc_unused __attribute__((unused)) #endif \ No newline at end of file diff --git a/libs/libc/include/sys/time.h b/libs/libc/include/sys/time.h new file mode 100644 index 00000000..39f5707f --- /dev/null +++ b/libs/libc/include/sys/time.h @@ -0,0 +1,26 @@ +#ifndef _SYS_TIME_H +#define _SYS_TIME_H + +#include +#include + +// Captures elapsed time with microsecond precision. +struct timeval +{ + time_t tv_sec; + suseconds_t tv_usec; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Retrieves the current time and stores it in tp. */ + __lc_is_deprecated int gettimeofday(struct timeval* tp, void* tzp); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/libs/libc/include/time.h b/libs/libc/include/time.h index c6180fd9..02db35f0 100644 --- a/libs/libc/include/time.h +++ b/libs/libc/include/time.h @@ -2,6 +2,7 @@ #define _TIME_H #include +#include #include // Structure representing broken-down time. @@ -18,13 +19,6 @@ struct tm int tm_isdst; }; -// Captures elapsed time with microsecond precision. -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - // Captures elapsed time with nanosecond precision. struct timespec { diff --git a/libs/libc/src/time.cpp b/libs/libc/src/time.cpp index 1c90cfc8..9d5d0334 100644 --- a/libs/libc/src/time.cpp +++ b/libs/libc/src/time.cpp @@ -110,6 +110,15 @@ extern "C" return (int)__lc_fast_syscall2(SYS_clock_gettime, clock_id, tp); } + int gettimeofday(struct timeval* tp, __lc_unused void* tzp) + { + struct timespec tspec; + clock_gettime(CLOCK_REALTIME, &tspec); + tp->tv_sec = tspec.tv_sec; + tp->tv_usec = tspec.tv_nsec / 1000; + return 0; + } + struct tm* localtime(const time_t* time) { static struct tm result;