annotate lib/localtime.c @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children 5a52ef2d4772
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18837
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Work around platform bugs in localtime.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
18837
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18875
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18837
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <time.h>
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
18846
661c3fb8962f New module 'localtime-buffer', split off from module 'gettimeofday'.
Bruno Haible <bruno@clisp.org>
parents: 18837
diff changeset
22 /* Keep consistent with localtime-buffer.c! */
18837
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #if !(GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME)
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 # include <stdlib.h>
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # include <string.h>
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 # undef localtime
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 struct tm *
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 rpl_localtime (const time_t *tp)
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
19595
beb2ad957aca Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
33 # if defined _WIN32 && ! defined __CYGWIN__
18875
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
34 /* Rectify the value of the environment variable TZ.
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
35 There are four possible kinds of such values:
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
36 - Traditional US time zone names, e.g. "PST8PDT". Syntax: see
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
37 <https://msdn.microsoft.com/en-us/library/90s5c885.aspx>
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
38 - Time zone names based on geography, that contain one or more
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
39 slashes, e.g. "Europe/Moscow".
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
40 - Time zone names based on geography, without slashes, e.g.
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
41 "Singapore".
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
42 - Time zone names that contain explicit DST rules. Syntax: see
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
43 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
44 The Microsoft CRT understands only the first kind. It produces incorrect
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
45 results if the value of TZ is of the other kinds.
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
46 But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
47 of the second kind for most geographies, or of the first kind in a few
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
48 other geographies. If it is of the second kind, neutralize it. For the
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
49 Microsoft CRT, an absent or empty TZ means the time zone that the user
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
50 has set in the Windows Control Panel.
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
51 If the value of TZ is of the third or fourth kind -- Cygwin programs
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
52 understand these syntaxes as well --, it does not matter whether we
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
53 neutralize it or not, since these values occur only when a Cygwin user
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
54 has set TZ explicitly; this case is 1. rare and 2. under the user's
affde4311db7 tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18846
diff changeset
55 responsibility. */
18837
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 const char *tz = getenv ("TZ");
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 if (tz != NULL && strchr (tz, '/') != NULL)
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 _putenv ("TZ=");
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 # endif
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 return localtime (tp);
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 }
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
8688d802c8d6 localtime: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 #endif