banan-os/userspace/libraries/LibC/sys/time.cpp

24 lines
574 B
C++
Raw Normal View History

#include <sys/syscall.h>
2024-07-31 23:24:23 +03:00
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
2024-07-31 23:24:23 +03:00
int gettimeofday(struct timeval* __restrict tp, void* __restrict tzp)
{
// If tzp is not a null pointer, the behavior is unspecified.
2024-12-02 08:27:38 +02:00
if (tzp != nullptr)
*static_cast<struct timezone*>(tzp) = {};
2024-07-31 23:24:23 +03:00
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
tp->tv_sec = ts.tv_sec;
tp->tv_usec = ts.tv_nsec / 1000;
return 0;
}
int setitimer(int which, const struct itimerval* __restrict value, struct itimerval* __restrict ovalue)
{
return syscall(SYS_SETITIMER, which, value, ovalue);
}