libc: Implement gettimeofday() and instantly mark it as deprecated
This commit is contained in:
parent
7bd1cba1e3
commit
f83c78bcad
@ -7,5 +7,6 @@
|
|||||||
#define __lc_is_deprecated __attribute__((deprecated))
|
#define __lc_is_deprecated __attribute__((deprecated))
|
||||||
#define __lc_unreachable __builtin_unreachable
|
#define __lc_unreachable __builtin_unreachable
|
||||||
#define __lc_used __attribute__((used))
|
#define __lc_used __attribute__((used))
|
||||||
|
#define __lc_unused __attribute__((unused))
|
||||||
|
|
||||||
#endif
|
#endif
|
26
libs/libc/include/sys/time.h
Normal file
26
libs/libc/include/sys/time.h
Normal 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
|
@ -2,6 +2,7 @@
|
|||||||
#define _TIME_H
|
#define _TIME_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
// Structure representing broken-down time.
|
// Structure representing broken-down time.
|
||||||
@ -18,13 +19,6 @@ struct tm
|
|||||||
int tm_isdst;
|
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.
|
// Captures elapsed time with nanosecond precision.
|
||||||
struct timespec
|
struct timespec
|
||||||
{
|
{
|
||||||
|
@ -110,6 +110,15 @@ extern "C"
|
|||||||
return (int)__lc_fast_syscall2(SYS_clock_gettime, clock_id, tp);
|
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)
|
struct tm* localtime(const time_t* time)
|
||||||
{
|
{
|
||||||
static struct tm result;
|
static struct tm result;
|
||||||
|
Loading…
Reference in New Issue
Block a user