From fd15708e6476164990e7b364dc5b2aa1600f8e89 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 11 May 2002 05:40:55 +0000 Subject: Begin the process of reworking the time functions for proper time zone and locale support (in theory). More work is still needed. -Erik --- libc/misc/time/asc_conv.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'libc/misc/time/asc_conv.c') diff --git a/libc/misc/time/asc_conv.c b/libc/misc/time/asc_conv.c index 78339dd6c..f5ab0a615 100644 --- a/libc/misc/time/asc_conv.c +++ b/libc/misc/time/asc_conv.c @@ -1,4 +1,5 @@ +#include #include #include /* @@ -16,29 +17,39 @@ * * Also fixed day conversion ... ANSI says no leading 0. * + * Modified Erik Andersen May 2002 + * Changed to optionally support real locales. + * */ -void __asctime(buffer, ptm) -register char *buffer; -struct tm *ptm; +#ifdef __UCLIBC_HAS_LOCALE__ +/* This is defined in locale/C-time.c in the GNU libc. */ +extern const struct locale_data _nl_C_LC_TIME; +extern const unsigned short int __mon_yday[2][13]; +# define __ab_weekday_name \ + (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string) +# define __ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string) +#else +extern char const __ab_weekday_name[][4]; +extern char const __ab_month_name[][4]; +#endif + +void __asctime(register char *buffer, struct tm *ptm) { - static const char days[] = "SunMonTueWedThuFriSat"; - static const char mons[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; - /* 012345678901234567890123456 */ - static const char template[] = "Err Err 00 00:00:00 0000\n"; - int tm_field[4]; - int tmp, i; char *p; + int tmp, i, tm_field[4]; + /* 012345678901234567890123456 */ + static const char template[] = "??? ??? 00 00:00:00 0000\n"; /* Since we need memcpy below, use it here instead of strcpy. */ memcpy(buffer, template, sizeof(template)); if ((ptm->tm_wday >= 0) && (ptm->tm_wday <= 6)) { - memcpy(buffer, days + 3 * (ptm->tm_wday), 3); + memcpy(buffer, __ab_weekday_name[ptm->tm_wday], 3); } if ((ptm->tm_mon >= 0) && (ptm->tm_mon <= 11)) { - memcpy(buffer + 4, mons + 3 * (ptm->tm_mon), 3); + memcpy(buffer + 4, __ab_month_name[ptm->tm_mon], 3); } tm_field[0] = ptm->tm_mday; -- cgit v1.2.3