From f0928164bd5bed20b121c9f2ec83756fc20c1dcd Mon Sep 17 00:00:00 2001 From: turbocat Date: Sun, 7 Nov 2021 19:29:12 +0000 Subject: [PATCH] libc.obj: fixed asctime() format and UTC mktime() bug. git-svn-id: svn://kolibrios.org@9260 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/source/time/asctime.c | 23 ++++++++++++------- .../ktcc/trunk/libc.obj/source/time/mktime.c | 6 ++--- .../ktcc/trunk/libc.obj/source/time/time.c | 4 +--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c index 3e5fa2b4e4..099c9a3797 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c @@ -1,3 +1,4 @@ +#include "stddef.h" #include #include #include @@ -9,18 +10,24 @@ const char *mon_str[12]={"Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", #pragma GCC push_options #pragma GCC optimize("O0") +#define TIME_STR_MAX 27 + char *asctime(const struct tm *tm){ - static char time_str[30]; - if(tm->tm_wday>7 || tm->tm_wday<1 || tm->tm_mon<1 || tm->tm_mon>12){ + if(!tm){ errno = EINVAL; return NULL; } - snprintf(time_str, 26, "%.3s %.3s%3d %2d:%2d:%2d %d\n", - wday_str[tm->tm_wday-1], - mon_str[tm->tm_mon-1], - tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec, - 1900 + tm->tm_year + if(tm->tm_wday>6 || tm->tm_wday<0 || tm->tm_mon<0 || tm->tm_mon>11){ + errno = EINVAL; + return NULL; + } + static char time_str[TIME_STR_MAX]; + snprintf(time_str, TIME_STR_MAX-1, "%.3s %.3s%3d %02d:%02d:%02d %d\n", + wday_str[tm->tm_wday], + mon_str[tm->tm_mon], + tm->tm_mday, tm->tm_hour, + tm->tm_min, tm->tm_sec, + 1900 + tm->tm_year ); return time_str; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c index a41c5c4f20..e5cbbae04f 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c @@ -2,7 +2,7 @@ time_t mktime (struct tm * timeptr) { - int utcdiff = -3; +// int utcdiff = -3; const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; unsigned long int tyears, tdays, leaps, utc_hrs; int i; @@ -17,7 +17,7 @@ time_t mktime (struct tm * timeptr) tdays += timeptr->tm_mday-1; // days of month passed. tdays = tdays + (tyears * 365) + leaps; - utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone. - return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec; +// utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone. + return (tdays * 86400) + (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/time.c b/programs/develop/ktcc/trunk/libc.obj/source/time/time.c index 1e772dfd1f..b53916a696 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/time.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/time.c @@ -1,9 +1,8 @@ #include #include -static struct tm __buffertime; - time_t time(time_t *timer){ + static struct tm __buffertime; int kos_date, kos_time; kos_date = _ksys_get_date().val; kos_time = _ksys_get_time().val; @@ -29,6 +28,5 @@ time_t time(time_t *timer){ if(timer){ *timer=ret; } - return ret; }