Added a bunch of stuff
This commit is contained in:
parent
66350160b0
commit
77c2abd247
66 changed files with 1808 additions and 0 deletions
39
time/time.c
Normal file
39
time/time.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <time.h>
|
||||
|
||||
#ifdef __is_libk
|
||||
#include <kernel/cmos.h>
|
||||
#endif
|
||||
|
||||
unsigned int get_days(unsigned int year, unsigned char month, unsigned char day) {
|
||||
unsigned int tot_days = day - 1;
|
||||
unsigned char month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
for(unsigned int i = 1970; i < year; i++) {
|
||||
if(i % 400 == 0 || (i % 100 != 0 && i % 4 == 0)) {
|
||||
tot_days += 366;
|
||||
}
|
||||
else {
|
||||
tot_days += 365;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < (month - 1); i++) {
|
||||
tot_days += month_days[i];
|
||||
}
|
||||
|
||||
return tot_days;
|
||||
}
|
||||
|
||||
time_t time(time_t * tloc) {
|
||||
time_t ret_val;
|
||||
|
||||
#ifdef __is_libk
|
||||
ret_val = read_rtc();
|
||||
#else
|
||||
/* TODO: Implement system calls for this stuff */
|
||||
#endif
|
||||
|
||||
if(tloc != 0) {
|
||||
*tloc = ret_val;
|
||||
}
|
||||
return ret_val;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue