Updated and fixed edit app; system call sys_getch () was rewrited for using memory...
[ZeXOS.git] / libc / time / localtime.c
blob4fe226513ef2f3316557a66ee956fbe5ae7dc60c
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <time.h>
23 #define MINUTE 60
24 #define HOUR (60 * MINUTE)
25 #define DAY (24 * HOUR)
26 #define YEAR (365 * DAY)
28 struct tm tmbuf;
30 /*
31 The localtime function converts the simple time pointed to by time to broken-down time representation,
32 expressed relative to the user's specified time zone.
33 The return value is a pointer to a static broken-down time structure,
34 which might be overwritten by subsequent calls to ctime, gmtime, or localtime.
35 (But no other library function overwrites the contents of this object.)
38 struct tm *localtime_r (const time_t *time, struct tm *resultp)
40 if (!resultp || !time)
41 return 0;
43 time_t c = *time;
45 resultp->tm_year = c/YEAR;
47 c -= resultp->tm_year * YEAR;
48 resultp->tm_mday = c / DAY;
50 c -= resultp->tm_mday * DAY;
51 resultp->tm_hour = c / HOUR;
53 c -= resultp->tm_hour * HOUR;
54 resultp->tm_min = c / MINUTE;
56 c -= resultp->tm_min * MINUTE;
57 resultp->tm_sec = c;
59 resultp->tm_year += EPOCH_YEAR;
60 resultp->tm_mday -= 8; // FIXME: hack
62 resultp->tm_wday = resultp->tm_mday;
64 while (resultp->tm_wday > 6)
65 resultp->tm_wday -= 7;
67 resultp->tm_isdst = 0;
69 return resultp;
72 /* NOTE: There is problem in multi-threaded application, because tmpbuf can be rewrited whenever */
73 struct tm *localtime (const time_t *time)
75 return localtime_r (time, &tmbuf);