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
44 #include <npe.h>
55
66 typedef long time_t;
7+typedef int clockid_t;
78
89 struct tm {
910 int tm_sec;
@@ -18,6 +19,16 @@ struct tm { · 8 unmodified lines
1819 char *tm_zone;
1920 };
2021
22+struct timespec {
23+ time_t tv_sec;
24+ long tv_nsec;
25+};
26+
27+enum {
28+ CLOCK_REALTIME,
29+ CLOCK_MONOTONIC,
30+};
31+
2132 #include <sys/time.h>
2233
2334 #define localtime npe_localtime
@@ -26,5 +37,6 @@ struct tm *npe_localtime(time_t *timep); · 2 unmodified lines
2637 struct tm *npe_gmtime(time_t *timep);
2738 size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
2839 time_t mktime(struct tm *tm);
40+int clock_gettime(clockid_t clockid, struct timespec *tp);
2941
3042 #endif
libnpe/clock_gettime.c+23−0
@@ -0,0 +1,23 @@
1+#include <errno.h>
2+#include <time.h>
3+#include "_npe.h"
4+
5+int
6+clock_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
1616 acosh.$O\
1717 basename.$O\
1818 cbrtf.$O\
19+ clock_gettime.$O\
1920 closedir.$O\
2021 dirfd.$O\
2122 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