Add some time stuff to libc

This commit is contained in:
K. Lange 2018-03-02 21:22:49 +09:00 committed by Kevin Lange
parent 9f7ea8db1d
commit 4ace4427d4
2 changed files with 17 additions and 0 deletions

View File

@ -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);

15
libc/time.c Normal file
View File

@ -0,0 +1,15 @@
#include <time.h>
#include <sys/time.h>
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);
}