meta: move photon/libc to root

This commit is contained in:
2026-02-08 20:45:25 +00:00
parent f00e74260d
commit 345a37962e
140 changed files with 0 additions and 0 deletions

22
libc/time/clock.c Normal file
View File

@@ -0,0 +1,22 @@
#include <time.h>
#include <sys/_time.h>
clock_t clock(void)
{
return __sys_clock();
}
int clock_getres(clockid_t clk_id, struct timespec *res)
{
return __sys_clock_getres(clk_id, res);
}
int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
return __sys_clock_gettime(clk_id, tp);
}
int clock_settime(clockid_t clk_id, const struct timespec *tp)
{
return __sys_clock_settime(clk_id, tp);
}

75
libc/time/gmtime.c Normal file
View File

@@ -0,0 +1,75 @@
#include <time.h>
#include <stdbool.h>
static struct tm g_time_struct = {};
/* to the suprise of nobody, this is from stack overflow.
* https://stackoverflow.com/questions/21593692/convert-unix-timestamp-to-date-without-system-libs
*/
struct tm *gmtime(const time_t *timer)
{
unsigned int seconds, minutes, hours, days, year, month;
unsigned int day_of_week;
seconds = *timer;
/* calculate minutes */
minutes = seconds / 60;
seconds -= minutes * 60;
/* calculate hours */
hours = minutes / 60;
minutes -= hours * 60;
/* calculate days */
days = hours / 24;
hours -= days * 24;
/* Unix time starts in 1970 on a Thursday */
year = 1970;
day_of_week = 4;
while(1) {
bool leap_year = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
uint16_t days_in_year = leap_year ? 366 : 365;
if (days >= days_in_year) {
day_of_week += leap_year ? 2 : 1;
days -= days_in_year;
if (day_of_week >= 7) {
day_of_week -= 7;
}
++year;
} else {
g_time_struct.tm_yday = days;
day_of_week += days;
day_of_week %= 7;
/* calculate the month and day */
static const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (month = 0; month < 12; ++month) {
uint8_t dim = days_in_month[month];
/* add a day to feburary if this is a leap year */
if (month == 1 && leap_year) {
++dim;
}
if (days >= dim) {
days -= dim;
} else {
break;
}
}
break;
}
}
g_time_struct.tm_sec = seconds;
g_time_struct.tm_min = minutes;
g_time_struct.tm_hour = hours;
g_time_struct.tm_mday = days + 1;
g_time_struct.tm_mon = month;
g_time_struct.tm_year = year - 1900;
g_time_struct.tm_wday = day_of_week;
return &g_time_struct;
}

7
libc/time/localtime.c Normal file
View File

@@ -0,0 +1,7 @@
#include <time.h>
struct tm *localtime(const time_t *timer)
{
/* TODO timezone support */
return gmtime(timer);
}

0
libc/time/mktime.c Normal file
View File

1151
libc/time/strftime.c Normal file

File diff suppressed because it is too large Load Diff

12
libc/time/time.c Normal file
View 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;
}

4
libc/time/tzset.c Normal file
View File

@@ -0,0 +1,4 @@
void tzset(void)
{
}