| 1 |
/* Provide tzset for systems that don't have it or for which it's broken. |
| 2 |
|
| 3 |
Copyright (C) 2001-2003, 2005-2007, 2009-2023 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This file is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as |
| 7 |
published by the Free Software Foundation, either version 3 of the |
| 8 |
License, or (at your option) any later version. |
| 9 |
|
| 10 |
This file 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. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public License |
| 16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
/* written by Jim Meyering */ |
| 19 |
|
| 20 |
#include <config.h> |
| 21 |
|
| 22 |
/* Specification. */ |
| 23 |
#include <time.h> |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
void |
| 29 |
rpl_tzset (void) |
| 30 |
#undef tzset |
| 31 |
{ |
| 32 |
#if defined _WIN32 && ! defined __CYGWIN__ |
| 33 |
/* Rectify the value of the environment variable TZ. |
| 34 |
There are four possible kinds of such values: |
| 35 |
- Traditional US time zone names, e.g. "PST8PDT". Syntax: see |
| 36 |
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset> |
| 37 |
- Time zone names based on geography, that contain one or more |
| 38 |
slashes, e.g. "Europe/Moscow". |
| 39 |
- Time zone names based on geography, without slashes, e.g. |
| 40 |
"Singapore". |
| 41 |
- Time zone names that contain explicit DST rules. Syntax: see |
| 42 |
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03> |
| 43 |
The Microsoft CRT understands only the first kind. It produces incorrect |
| 44 |
results if the value of TZ is of the other kinds. |
| 45 |
But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value |
| 46 |
of the second kind for most geographies, or of the first kind in a few |
| 47 |
other geographies. If it is of the second kind, neutralize it. For the |
| 48 |
Microsoft CRT, an absent or empty TZ means the time zone that the user |
| 49 |
has set in the Windows Control Panel. |
| 50 |
If the value of TZ is of the third or fourth kind -- Cygwin programs |
| 51 |
understand these syntaxes as well --, it does not matter whether we |
| 52 |
neutralize it or not, since these values occur only when a Cygwin user |
| 53 |
has set TZ explicitly; this case is 1. rare and 2. under the user's |
| 54 |
responsibility. */ |
| 55 |
const char *tz = getenv ("TZ"); |
| 56 |
if (tz != NULL && strchr (tz, '/') != NULL) |
| 57 |
_putenv ("TZ="); |
| 58 |
|
| 59 |
/* On native Windows, tzset() is deprecated. Use _tzset() instead. See |
| 60 |
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-tzset> |
| 61 |
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset> */ |
| 62 |
_tzset (); |
| 63 |
#else |
| 64 |
tzset (); |
| 65 |
#endif |
| 66 |
} |