History

npe: add clock_gettime

zamfofex committed 2 years ago

Commit 720ba971 parent 85aac113 files · +36 −0Browse files

Unified · Split

3 files
  1. include/npe/time.h +12 −0
  2. libnpe/clock_gettime.c +23 −0
  3. libnpe/mkfile +1 −0
include/npe/time.h+12−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
4#include <npe.h>4#include <npe.h>
5 5
6typedef long time_t;6typedef long time_t;
7typedef int clockid_t;
7 8
8struct tm {9struct tm {
9 int tm_sec;10 int tm_sec;
@@ -18,6 +19,16 @@ struct tm { · 8 unmodified lines
18 char *tm_zone;19 char *tm_zone;
19};20};
20 21
22struct timespec {
23 time_t tv_sec;
24 long tv_nsec;
25};
26
27enum {
28 CLOCK_REALTIME,
29 CLOCK_MONOTONIC,
30};
31
21#include <sys/time.h>32#include <sys/time.h>
22 33
23#define localtime npe_localtime34#define localtime npe_localtime
@@ -26,5 +37,6 @@ struct tm *npe_localtime(time_t *timep); · 2 unmodified lines
26struct tm *npe_gmtime(time_t *timep);37struct tm *npe_gmtime(time_t *timep);
27size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);38size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
28time_t mktime(struct tm *tm);39time_t mktime(struct tm *tm);
40int clock_gettime(clockid_t clockid, struct timespec *tp);
29 41
30#endif42#endif
libnpe/clock_gettime.c+23−0
@@ -0,0 +1,23 @@
1#include <errno.h>
2#include <time.h>
3#include "_npe.h"
4
5int
6clock_gettime(clockid_t clockid, struct timespec *tp)
7{
8 uvlong t;
9
10 if(clockid == CLOCK_REALTIME)
11 t = nsec();
12 else if(clockid == CLOCK_MONOTONIC)
13 t = npe_nanosec();
14 else{
15 errno = EINVAL;
16 return -1;
17 }
18
19 tp->tv_nsec = t % 1000000000;
20 tp->tv_sec = t / 1000000000;
21
22 return 0;
23}
libnpe/mkfile+1−0
@@ -16,6 +16,7 @@ OFILES=\ · 15 unmodified lines
16 acosh.$O\16 acosh.$O\
17 basename.$O\17 basename.$O\
18 cbrtf.$O\18 cbrtf.$O\
19 clock_gettime.$O\
19 closedir.$O\20 closedir.$O\
20 dirfd.$O\21 dirfd.$O\
21 dirname.$O\22 dirname.$O\

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t