libc: Add gettimeofday()
This commit is contained in:
parent
dc169124cc
commit
a7c6163e7c
@ -1,4 +1,4 @@
|
|||||||
/* bits/timespec.h: The timespec structure. */
|
/* bits/timespec.h: The timespec and timeval structures. */
|
||||||
|
|
||||||
#ifndef _BITS_TIMESPEC_H
|
#ifndef _BITS_TIMESPEC_H
|
||||||
#define _BITS_TIMESPEC_H
|
#define _BITS_TIMESPEC_H
|
||||||
@ -11,4 +11,10 @@ struct timespec
|
|||||||
long tv_nsec;
|
long tv_nsec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct timeval
|
||||||
|
{
|
||||||
|
time_t tv_sec;
|
||||||
|
suseconds_t tv_usec;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
21
libc/include/sys/time.h
Normal file
21
libc/include/sys/time.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* sys/time.h: POSIX time types. */
|
||||||
|
|
||||||
|
#ifndef _SYS_TIME_H
|
||||||
|
#define _SYS_TIME_H
|
||||||
|
|
||||||
|
#include <bits/attrs.h>
|
||||||
|
#include <bits/timespec.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Get the current time of day. */
|
||||||
|
__deprecated int gettimeofday(struct timeval* tp, void* timezone);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -19,6 +19,7 @@ typedef __u64_t ino_t;
|
|||||||
typedef __u32_t uid_t;
|
typedef __u32_t uid_t;
|
||||||
typedef __u32_t gid_t;
|
typedef __u32_t gid_t;
|
||||||
typedef __u64_t nlink_t;
|
typedef __u64_t nlink_t;
|
||||||
|
typedef __i64_t suseconds_t;
|
||||||
|
|
||||||
typedef off_t fpos_t;
|
typedef off_t fpos_t;
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <bits/errno-return.h>
|
#include <bits/errno-return.h>
|
||||||
#include <luna/Check.h>
|
#include <luna/Check.h>
|
||||||
#include <luna/Format.h>
|
#include <luna/Format.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -148,4 +150,21 @@ extern "C"
|
|||||||
{
|
{
|
||||||
return asctime(localtime(tp));
|
return asctime(localtime(tp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gettimeofday(struct timeval* tp, void* timezone)
|
||||||
|
{
|
||||||
|
if (timezone)
|
||||||
|
{
|
||||||
|
fputs("gettimeofday: timezone was not NULL, abort\n", stderr);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec ts;
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &ts) < 0) return -1;
|
||||||
|
|
||||||
|
tp->tv_sec = ts.tv_sec;
|
||||||
|
tp->tv_usec = ts.tv_nsec / 1000;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user