LibC: Implement gettimeofday()

This commit is contained in:
Bananymous 2024-07-31 23:24:23 +03:00
parent 7c3b6307d9
commit fc6c39e670
2 changed files with 16 additions and 0 deletions

View File

@ -23,6 +23,7 @@ set(LIBC_SOURCES
sys/select.cpp
sys/socket.cpp
sys/stat.cpp
sys/time.cpp
sys/wait.cpp
termios.cpp
time.cpp

View File

@ -0,0 +1,15 @@
#include <sys/time.h>
#include <time.h>
int gettimeofday(struct timeval* __restrict tp, void* __restrict tzp)
{
// If tzp is not a null pointer, the behavior is unspecified.
(void)tzp;
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
tp->tv_sec = ts.tv_sec;
tp->tv_usec = ts.tv_nsec / 1000;
return 0;
}