Added time() and clock()
This commit is contained in:
@@ -27,7 +27,7 @@ set(CMAKE_EXE_LINKER_FLAGS
|
||||
|
||||
set(malloc_impl dlmalloc)
|
||||
set(photon_libc_sources "")
|
||||
set(generic_dirs string stdio stdlib errno internal ctype wchar)
|
||||
set(generic_dirs string stdio stdlib errno internal ctype wchar time)
|
||||
|
||||
message(STATUS "Memory allocator: ${malloc_impl}")
|
||||
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
#ifndef TIME_H_
|
||||
#define TIME_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/_time.h>
|
||||
|
||||
#define CLOCKS_PER_SEC __SYS_CLOCKS_PER_SEC
|
||||
|
||||
struct timespec {
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
|
||||
struct tm {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
};
|
||||
|
||||
extern clock_t clock(void);
|
||||
extern time_t time(time_t *p);
|
||||
|
||||
extern struct tm *gmtime(const time_t *timer);
|
||||
extern struct tm *localtime(const time_t *timer);
|
||||
extern time_t mktime(struct tm *timeptr);
|
||||
extern size_t strftime(char *str, size_t max, const char *format, const struct tm *timeptr);
|
||||
|
||||
#endif
|
||||
|
||||
9
photon/libc/sys/horizon/__time.h
Normal file
9
photon/libc/sys/horizon/__time.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef SYS_HORIZON___TIME_H_
|
||||
#define SYS_HORIZON___TIME_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern clock_t __sys_clock(void);
|
||||
extern time_t __sys_time(void);
|
||||
|
||||
#endif
|
||||
6
photon/libc/sys/horizon/sys/_time.h
Normal file
6
photon/libc/sys/horizon/sys/_time.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef SYS_HORIZON___TIME_H_
|
||||
#define SYS_HORIZON___TIME_H_
|
||||
|
||||
#define __SYS_CLOCKS_PER_SEC 1000000000
|
||||
|
||||
#endif
|
||||
19
photon/libc/sys/horizon/time.c
Normal file
19
photon/libc/sys/horizon/time.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <magenta/types.h>
|
||||
#include <magenta/clock.h>
|
||||
#include <time.h>
|
||||
|
||||
clock_t __sys_clock(void)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_clock_get_time(MX_CLOCK_MONOTONIC, &v);
|
||||
|
||||
return (v.sec * CLOCKS_PER_SEC) + v.nsec;
|
||||
}
|
||||
|
||||
time_t __sys_time(void)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_clock_get_time(MX_CLOCK_REALTIME, &v);
|
||||
|
||||
return v.sec;
|
||||
}
|
||||
7
photon/libc/time/clock.c
Normal file
7
photon/libc/time/clock.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <time.h>
|
||||
#include <__time.h>
|
||||
|
||||
clock_t clock(void)
|
||||
{
|
||||
return __sys_clock();
|
||||
}
|
||||
0
photon/libc/time/gmtime.c
Normal file
0
photon/libc/time/gmtime.c
Normal file
0
photon/libc/time/localtime.c
Normal file
0
photon/libc/time/localtime.c
Normal file
0
photon/libc/time/mktime.c
Normal file
0
photon/libc/time/mktime.c
Normal file
0
photon/libc/time/strftime.c
Normal file
0
photon/libc/time/strftime.c
Normal file
12
photon/libc/time/time.c
Normal file
12
photon/libc/time/time.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <time.h>
|
||||
#include <__time.h>
|
||||
|
||||
time_t time(time_t *p)
|
||||
{
|
||||
time_t out = __sys_time();
|
||||
if (p) {
|
||||
*p = out;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user