1 /*
2 * KCemu -- The emulator for the KC85 homecomputer series and much more.
3 * Copyright (C) 1997-2010 Torsten Paul
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
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 General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <time.h>
21 #include <stdio.h>
22
23 #include "kc/config.h"
24 #include "sys/sysdep.h"
25
26 #if HAVE_LOCALTIME_R
27
28 void
sys_converttime(long time,int * year,int * month,int * day,int * hour,int * minute,int * second)29 sys_converttime(long time, int *year, int *month, int *day, int *hour, int *minute, int *second)
30 {
31 time_t t = time;
32 struct tm result;
33
34 localtime_r(&t, &result);
35
36 *year = result.tm_year;
37 *month = result.tm_mon + 1;
38 *day = result.tm_mday;
39 *hour = result.tm_hour;
40 *minute = result.tm_min;
41 *second = result.tm_sec;
42 }
43
44 #else /* HAVE_LOCALTIME_R */
45 #if HAVE_LOCALTIME
46
47 void
sys_localtime(long time,int * year,int * month,int * day,int * hour,int * minute,int * second)48 sys_localtime(long time, int *year, int *month, int *day, int *hour, int *minute, int *second)
49 {
50 time_t t = time;
51 struct tm *result;
52
53 result = localtime(&t);
54
55 *year = result->tm_year;
56 *month = result->tm_mon + 1;
57 *day = result->tm_mday;
58 *hour = result->tm_hour;
59 *minute = result->tm_min;
60 *second = result->tm_sec;
61 }
62
63 #else /* HAVE_LOCALTIME */
64 #error neither HAVE_LOCALTIME_R nor HAVE_LOCALTIME defined
65 #endif /* HAVE_LOCALTIME */
66 #endif /* HAVE_LOCALTIME_R */
67