~ft/npe

720ba9765a63caefebafc4d2923dd10febfe99e9 — zamfofex 4 months ago 85aac11
npe: add clock_gettime
3 files changed, 36 insertions(+), 0 deletions(-)

M include/npe/time.h
A libnpe/clock_gettime.c
M libnpe/mkfile
M include/npe/time.h => include/npe/time.h +12 -0
@@ 4,6 4,7 @@
#include <npe.h>

typedef long time_t;
typedef int clockid_t;

struct tm {
	int tm_sec;


@@ 18,6 19,16 @@ struct tm {
	char *tm_zone;
};

struct timespec {
	time_t tv_sec;
	long tv_nsec;
};

enum {
	CLOCK_REALTIME,
	CLOCK_MONOTONIC,
};

#include <sys/time.h>

#define localtime npe_localtime


@@ 26,5 37,6 @@ struct tm *npe_localtime(time_t *timep);
struct tm *npe_gmtime(time_t *timep);
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
time_t mktime(struct tm *tm);
int clock_gettime(clockid_t clockid, struct timespec *tp);

#endif

A libnpe/clock_gettime.c => libnpe/clock_gettime.c +23 -0
@@ 0,0 1,23 @@
#include <errno.h>
#include <time.h>
#include "_npe.h"

int
clock_gettime(clockid_t clockid, struct timespec *tp)
{
	uvlong t;

	if(clockid == CLOCK_REALTIME)
		t = nsec();
	else if(clockid == CLOCK_MONOTONIC)
		t = npe_nanosec();
	else{
		errno = EINVAL;
		return -1;
	}

	tp->tv_nsec = t % 1000000000;
	tp->tv_sec = t / 1000000000;

	return 0;
}

M libnpe/mkfile => libnpe/mkfile +1 -0
@@ 16,6 16,7 @@ OFILES=\
	acosh.$O\
	basename.$O\
	cbrtf.$O\
	clock_gettime.$O\
	closedir.$O\
	dirfd.$O\
	dirname.$O\