libc: Implement gettimeofday() and instantly mark it as deprecated

This commit is contained in:
apio 2022-10-30 20:40:05 +01:00
parent 7bd1cba1e3
commit f83c78bcad
4 changed files with 37 additions and 7 deletions

View File

@ -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

View File

@ -0,0 +1,26 @@
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <bits/macros.h>
#include <sys/types.h>
// 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

View File

@ -2,6 +2,7 @@
#define _TIME_H
#include <stddef.h>
#include <sys/time.h>
#include <sys/types.h>
// 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
{

View File

@ -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;