forked from KolibriOS/kolibrios
libc.obj: fixed asctime() format and UTC mktime() bug.
git-svn-id: svn://kolibrios.org@9260 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
2eddf0b1c0
commit
f0928164bd
@ -1,3 +1,4 @@
|
|||||||
|
#include "stddef.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -9,18 +10,24 @@ const char *mon_str[12]={"Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug",
|
|||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize("O0")
|
#pragma GCC optimize("O0")
|
||||||
|
|
||||||
|
#define TIME_STR_MAX 27
|
||||||
|
|
||||||
char *asctime(const struct tm *tm){
|
char *asctime(const struct tm *tm){
|
||||||
static char time_str[30];
|
if(!tm){
|
||||||
if(tm->tm_wday>7 || tm->tm_wday<1 || tm->tm_mon<1 || tm->tm_mon>12){
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(time_str, 26, "%.3s %.3s%3d %2d:%2d:%2d %d\n",
|
if(tm->tm_wday>6 || tm->tm_wday<0 || tm->tm_mon<0 || tm->tm_mon>11){
|
||||||
wday_str[tm->tm_wday-1],
|
errno = EINVAL;
|
||||||
mon_str[tm->tm_mon-1],
|
return NULL;
|
||||||
tm->tm_mday, tm->tm_hour,
|
}
|
||||||
tm->tm_min, tm->tm_sec,
|
static char time_str[TIME_STR_MAX];
|
||||||
1900 + tm->tm_year
|
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;
|
return time_str;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
time_t mktime (struct tm * timeptr)
|
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};
|
const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
unsigned long int tyears, tdays, leaps, utc_hrs;
|
unsigned long int tyears, tdays, leaps, utc_hrs;
|
||||||
int i;
|
int i;
|
||||||
@ -17,7 +17,7 @@ time_t mktime (struct tm * timeptr)
|
|||||||
tdays += timeptr->tm_mday-1; // days of month passed.
|
tdays += timeptr->tm_mday-1; // days of month passed.
|
||||||
tdays = tdays + (tyears * 365) + leaps;
|
tdays = tdays + (tyears * 365) + leaps;
|
||||||
|
|
||||||
utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
|
// utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
|
||||||
return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
|
return (tdays * 86400) + (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/ksys.h>
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
static struct tm __buffertime;
|
|
||||||
|
|
||||||
time_t time(time_t *timer){
|
time_t time(time_t *timer){
|
||||||
|
static struct tm __buffertime;
|
||||||
int kos_date, kos_time;
|
int kos_date, kos_time;
|
||||||
kos_date = _ksys_get_date().val;
|
kos_date = _ksys_get_date().val;
|
||||||
kos_time = _ksys_get_time().val;
|
kos_time = _ksys_get_time().val;
|
||||||
@ -29,6 +28,5 @@ time_t time(time_t *timer){
|
|||||||
if(timer){
|
if(timer){
|
||||||
*timer=ret;
|
*timer=ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user