1.0.5.35: stack alignment on x86/Darwin, once more
[sbcl.git] / src / runtime / time.c
blob82ffab2c528e20b0d2a8e608413b606de695ce23
1 /*
2 * time support routines that are easier to do in C than in Lisp
3 */
5 /*
6 * This software is part of the SBCL system. See the README file for
7 * more information.
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
16 #include <stdio.h>
17 #include <time.h>
18 #include "sbcl.h"
19 #include "runtime.h"
21 void get_timezone(time_t when, int *secwest, boolean *dst)
23 struct tm ltm, gtm;
24 int sw;
26 #ifdef LISP_FEATURE_WIN32
27 /* No _r versions on Windows, but the API documentation also
28 * doesn't warn them about being non-reentrant... So here's
29 * hoping they actually are -- once Windows grows threads
30 * this better be checked, though.
32 * The Windows versions also don't support times before the
33 * epoch, so we kludge it. */
34 if (when < 0)
35 when = 0;
36 ltm = *localtime(&when);
37 gtm = *gmtime(&when);
38 #else
39 ltm = *localtime_r(&when, &ltm);
40 gtm = *gmtime_r(&when, &gtm);
41 #endif
43 sw = (((gtm.tm_hour*60)+gtm.tm_min)*60+gtm.tm_sec) - (((ltm.tm_hour*60)+ltm.tm_min)*60+ltm.tm_sec);
44 if ((gtm.tm_wday + 1) % 7 == ltm.tm_wday)
45 sw -= 24*3600;
46 else if (gtm.tm_wday == (ltm.tm_wday + 1) % 7)
47 sw += 24*3600;
48 *secwest = sw;
49 *dst = ltm.tm_isdst;