From 4ace4427d4b7432bfa4ad1c1a00fd4ecb0c98121 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 2 Mar 2018 21:22:49 +0900 Subject: [PATCH] Add some time stuff to libc --- include/time.h | 2 ++ libc/time.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 libc/time.c diff --git a/include/time.h b/include/time.h index 0186d29d..5157986d 100644 --- a/include/time.h +++ b/include/time.h @@ -17,3 +17,5 @@ struct tm { extern struct tm *localtime(const time_t *timep); extern size_t strftime(char *s, size_t max, const char *format, const struct tm *tm); +extern time_t time(time_t * out); +extern double difftime(time_t a, time_t b); diff --git a/libc/time.c b/libc/time.c new file mode 100644 index 00000000..159b0309 --- /dev/null +++ b/libc/time.c @@ -0,0 +1,15 @@ +#include +#include + +time_t time(time_t * out) { + struct timeval p; + gettimeofday(&p, NULL); + if (out) { + *out = p.tv_sec; + } + return p.tv_sec; +} + +double difftime(time_t a, time_t b) { + return (double)(a - b); +}