Merge pull request #210 from Dennisbonke/time-stuff
options/ansi: Add several time related functions
This commit is contained in:
commit
8005e83b84
|
@ -3,6 +3,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -29,10 +30,19 @@ static file_window *get_localtime_window() {
|
|||
return &window;
|
||||
}
|
||||
|
||||
// Function taken from musl
|
||||
clock_t clock(void) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
struct timespec ts;
|
||||
|
||||
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
|
||||
return -1;
|
||||
|
||||
if(ts.tv_sec > LONG_MAX / 1000000 || ts.tv_nsec / 1000 > LONG_MAX - 1000000 * ts.tv_sec)
|
||||
return -1;
|
||||
|
||||
return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
|
||||
}
|
||||
|
||||
double difftime(time_t a, time_t b){
|
||||
return a - b;
|
||||
}
|
||||
|
@ -40,9 +50,15 @@ time_t mktime(struct tm *ptr){
|
|||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
int timespec_get(struct timespec *ptr, int base){
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
|
||||
/* There is no other implemented value than TIME_UTC; all other values
|
||||
* are considered erroneous. */
|
||||
// Function taken from musl
|
||||
int timespec_get(struct timespec *ts, int base) {
|
||||
if(base != TIME_UTC)
|
||||
return 0;
|
||||
int ret = clock_gettime(CLOCK_REALTIME, ts);
|
||||
return ret < 0 ? 0 : base;
|
||||
}
|
||||
|
||||
char *asctime(const struct tm *ptr){
|
||||
|
@ -514,6 +530,16 @@ struct tm *localtime_r(const time_t *unix_gmt, struct tm *res) {
|
|||
return res;
|
||||
}
|
||||
|
||||
char *asctime_r(const struct tm *tm, char *buf) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
char *ctime_r(const time_t *, char *) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
char *strptime(const char *__restrict, const char *__restrict,
|
||||
struct tm *__restrict) {
|
||||
__ensure(!"Not implemented");
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// [7.27.1] Components of time
|
||||
|
||||
#define CLOCKS_PER_SEC 1000000000
|
||||
#define CLOCKS_PER_SEC ((clock_t)1000000)
|
||||
|
||||
#define TIME_UTC 1
|
||||
|
||||
|
@ -98,6 +98,8 @@ int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
|
|||
int clock_settime(clockid_t, const struct timespec *);
|
||||
|
||||
struct tm *localtime_r(const time_t *, struct tm *);
|
||||
char *asctime_r(const struct tm *tm, char *buf);
|
||||
char *ctime_r(const time_t *, char *);
|
||||
|
||||
char *strptime(const char *__restrict, const char *__restrict,
|
||||
struct tm *__restrict);
|
||||
|
|
Loading…
Reference in a new issue