From: John Hodge Date: Sun, 9 Mar 2014 07:08:31 +0000 (+0800) Subject: Usermode/libc - Time formatting, stub locale.h, rename/remove X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=41f5d1923eac00f90097f80e51f0c1f8d1ab7cb3;p=tpg%2Facess2.git Usermode/libc - Time formatting, stub locale.h, rename/remove --- diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 3c18c28d..c615b6e9 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -10,9 +10,10 @@ LDFLAGS += -Map map.txt INCFILES := stdio.h stdlib.h -OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o rand.o -OBJ += scanf.o signals.o strtoi.o strtof.o +OBJ = stub.o heap.o stdlib.o env.o string.o rand.o +OBJ += scanf.o signals.o strtoi.o strtof.o OBJ += printf.o time.o timeconv.o errno.o ctype.o +OBJ += stdio.o stdio_files.o OBJ += arch/$(ARCHDIR).ao # signals.o DEPFILES := $(OBJ:%.o=%.d) diff --git a/Usermode/Libraries/libc.so_src/include_exp/locale.h b/Usermode/Libraries/libc.so_src/include_exp/locale.h new file mode 100644 index 00000000..802e8200 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/include_exp/locale.h @@ -0,0 +1,22 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * locale.h + * - Locale management + */ +#ifndef _LIBC_LOCALE_H_ +#define _LIBC_LOCALE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/Usermode/Libraries/libc.so_src/include_exp/time.h b/Usermode/Libraries/libc.so_src/include_exp/time.h index 4c8d3ea6..c06d128c 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/time.h +++ b/Usermode/Libraries/libc.so_src/include_exp/time.h @@ -55,7 +55,7 @@ extern char *asctime_r(const struct tm *timeptr, char *buf); //! asctime(localtime(timer)) extern char *ctime(const time_t *timer); -extern char *ctime_r(const time_t *timer, struct tm *result); +extern char *ctime_r(const time_t *timer, char *buf); //! Convert \a timter into UTC extern struct tm *gmtime(const time_t *timer); diff --git a/Usermode/Libraries/libc.so_src/stdio.c b/Usermode/Libraries/libc.so_src/stdio.c index a944f9b6..1bb90cd9 100644 --- a/Usermode/Libraries/libc.so_src/stdio.c +++ b/Usermode/Libraries/libc.so_src/stdio.c @@ -755,7 +755,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) EXPORT int fputs(const char *s, FILE *fp) { int len = strlen(s); - return fwrite(s, 1, len, fp); + return fwrite(s, len, 1, fp); } /** diff --git a/Usermode/Libraries/libc.so_src/stdio_files.c b/Usermode/Libraries/libc.so_src/stdio_files.c new file mode 100644 index 00000000..cae4f8bd --- /dev/null +++ b/Usermode/Libraries/libc.so_src/stdio_files.c @@ -0,0 +1,23 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * stdio_files.c + * - non-stream file manipulation + */ +#include +#include // _SysDebug + +// === CODE === +int remove(const char *filename) +{ + _SysDebug("TODO: libc remove('%s')", filename); + return 1; +} + +int rename(const char *old, const char *new) +{ + _SysDebug("TODO: libc rename('%s','%s')", old, new); + return 1; +} + diff --git a/Usermode/Libraries/libc.so_src/time.c b/Usermode/Libraries/libc.so_src/time.c index 330b6a7d..185af88f 100644 --- a/Usermode/Libraries/libc.so_src/time.c +++ b/Usermode/Libraries/libc.so_src/time.c @@ -10,6 +10,7 @@ #include #include "timeconv.h" #include +#include // sprintf #define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years @@ -44,6 +45,54 @@ time_t time(time_t *t) return ret; } +//! Convert the time structure into a string of form 'Sun Sep 16 01:03:52 1973\n\0' +char *asctime(const struct tm *timeptr) +{ + static char staticbuf[sizeof("Sun Sep 16 01:03:52 1973\n")]; + return asctime_r(timeptr, staticbuf); +} +char *asctime_r(const struct tm *timeptr, char *buf) +{ + const char *WDAYS[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; + const char *MONS[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; + sprintf(buf, + "%s %s %i %02i:%02i:%02i %4i\n", + WDAYS[timeptr->tm_wday], + MONS[timeptr->tm_mon], + timeptr->tm_mday, + timeptr->tm_hour, + timeptr->tm_min, + timeptr->tm_sec, + timeptr->tm_year + ); + return buf; +} + +//! asctime(localtime(timer)) +char *ctime(const time_t *timer) +{ + struct tm time_buf; + localtime_r(timer, &time_buf); + return asctime(&time_buf); +} +extern char *ctime_r(const time_t *timer, char *buf) +{ + struct tm time_buf; + localtime_r(timer, &time_buf); + return asctime_r(&time_buf, buf); +} + +//! Convert \a timter into UTC +struct tm *gmtime(const time_t *timer) +{ + // Ignore UTC + return localtime(timer); +} +struct tm *gmtime_r(const time_t *timer, struct tm *result) +{ + return localtime_r(timer, result); +} + static struct tm static_tm; struct tm *localtime(const time_t *timer) @@ -65,6 +114,7 @@ struct tm *localtime_r(const time_t *timer, struct tm *ret) // Month and Day of Month get_month_day(ret->tm_yday, is_ly, &ret->tm_mon, &ret->tm_mday); + ret->tm_mon --; ret->tm_isdst = 0; // Fuck DST