2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
26 * Converts date and time to a string
27 * @param timeptr Date and time
30 char *asctime(const struct tm
*timeptr
) {
31 char *wday_name
[] = {"Sun","Mon","Tue","Wed","Thu", "Fri","Sat"};
32 char *mon_name
[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
33 static char result
[26];
34 sprintf(result
,"%s %s %u %02u:%02u:%02u %u\n",wday_name
[timeptr
->tm_wday
],mon_name
[timeptr
->tm_mon
],timeptr
->tm_mday
,timeptr
->tm_hour
,timeptr
->tm_min
, timeptr
->tm_sec
,1900+timeptr
->tm_year
);
39 * Builds timestamp from date and time
40 * @param tm Time and date
43 time_t mktime(struct tm
*tm
) {
44 return tm
->tm_sec
+ tm
->tm_min
*60 + tm
->tm_hour
*3600 + tm
->tm_yday
*86400 +
45 (tm
->tm_year
-70)*31536000 + ((tm
->tm_year
-69)/4)*86400 -
46 ((tm
->tm_year
-1)/100)*86400 + ((tm
->tm_year
+299)/400)*86400;
51 * @param tloc Reference for timestamp
54 time_t time(time_t *tloc
) {
56 gettimeofday(&tp
,NULL
);
57 if (tloc
!=NULL
) *tloc
= tp
.tv_sec
;
62 * Returns number of ticks since process start
66 return syscall_call(SYSCALL_TIME_GETTICKS
,0);