POSIX/C11: add timespec_get()

Change-Id: I746e32f3a463bf2c7b03097c625901d54cf2b8eb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4853
Reviewed-by: Rene Gollent <rene@gollent.com>
This commit is contained in:
Jérôme Duval 2022-01-10 15:34:59 +01:00 committed by Rene Gollent
parent 6f62f45641
commit a7115745f2
2 changed files with 29 additions and 0 deletions

View File

@ -25,6 +25,7 @@ typedef __haiku_int64 time_t;
#define CLOCKS_PER_SEC 1000000
#define CLK_TCK CLOCKS_PER_SEC
#define TIME_UTC 1
#define MAX_TIMESTR 70
/* 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);
int timer_getoverrun(timer_t timerID);
/* C11 timespec */
int timespec_get(struct timespec *ts, int base);
/* special timezone support */
extern void tzset(void);

View File

@ -0,0 +1,25 @@
/*
* Copyright 2022, Jérôme Duval, jerome.duval@gmail.com.
* 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;
}