From fc6c39e670289861146487c644a916a40648525d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 31 Jul 2024 23:24:23 +0300 Subject: [PATCH] LibC: Implement gettimeofday() --- userspace/libraries/LibC/CMakeLists.txt | 1 + userspace/libraries/LibC/sys/time.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 userspace/libraries/LibC/sys/time.cpp diff --git a/userspace/libraries/LibC/CMakeLists.txt b/userspace/libraries/LibC/CMakeLists.txt index b5a8b0541b..1c6036eb13 100644 --- a/userspace/libraries/LibC/CMakeLists.txt +++ b/userspace/libraries/LibC/CMakeLists.txt @@ -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 diff --git a/userspace/libraries/LibC/sys/time.cpp b/userspace/libraries/LibC/sys/time.cpp new file mode 100644 index 0000000000..27637d3390 --- /dev/null +++ b/userspace/libraries/LibC/sys/time.cpp @@ -0,0 +1,15 @@ +#include +#include + +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; +}