POSIX/C11: add timespec_get()
Change-Id: I746e32f3a463bf2c7b03097c625901d54cf2b8eb Reviewed-on: https://review.haiku-os.org/c/haiku/+/4853 Reviewed-by: Rene Gollent <[email protected]>
This commit is contained in:
committed by
Rene Gollent
parent
6f62f45641
commit
a7115745f2
@@ -25,6 +25,7 @@ typedef __haiku_int64 time_t;
|
|||||||
|
|
||||||
#define CLOCKS_PER_SEC 1000000
|
#define CLOCKS_PER_SEC 1000000
|
||||||
#define CLK_TCK CLOCKS_PER_SEC
|
#define CLK_TCK CLOCKS_PER_SEC
|
||||||
|
#define TIME_UTC 1
|
||||||
|
|
||||||
#define MAX_TIMESTR 70
|
#define MAX_TIMESTR 70
|
||||||
/* maximum length of a string returned by asctime(), and ctime() */
|
/* maximum length of a string returned by asctime(), and ctime() */
|
||||||
@@ -110,6 +111,9 @@ int timer_settime(timer_t timerID, int flags,
|
|||||||
const struct itimerspec* value, struct itimerspec* oldValue);
|
const struct itimerspec* value, struct itimerspec* oldValue);
|
||||||
int timer_getoverrun(timer_t timerID);
|
int timer_getoverrun(timer_t timerID);
|
||||||
|
|
||||||
|
/* C11 timespec */
|
||||||
|
int timespec_get(struct timespec *ts, int base);
|
||||||
|
|
||||||
/* special timezone support */
|
/* special timezone support */
|
||||||
extern void tzset(void);
|
extern void tzset(void);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022, Jérôme Duval, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
timespec_get(struct timespec* time, int base)
|
||||||
|
{
|
||||||
|
if (base != TIME_UTC)
|
||||||
|
return 0;
|
||||||
|
bigtime_t microSeconds = real_time_clock_usecs();
|
||||||
|
|
||||||
|
// set the result
|
||||||
|
time->tv_sec = microSeconds / 1000000;
|
||||||
|
time->tv_nsec = (microSeconds % 1000000) * 1000;
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user