root/maint/gnulib/lib/wcsftime.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. rpl_wcsftime

   1 /* Work around platform bugs in wcsftime.
   2    Copyright (C) 2017-2021 Free Software Foundation, Inc.
   3 
   4    This file is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU Lesser General Public License as
   6    published by the Free Software Foundation; either version 2.1 of the
   7    License, or (at your option) any later version.
   8 
   9    This file is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU Lesser General Public License for more details.
  13 
  14    You should have received a copy of the GNU Lesser General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 #include <config.h>
  18 
  19 /* Specification.  */
  20 #include <wchar.h>
  21 
  22 #include <stdlib.h>
  23 #include <string.h>
  24 #include <time.h>
  25 
  26 #undef wcsftime
  27 
  28 size_t
  29 rpl_wcsftime (wchar_t *buf, size_t bufsize, const wchar_t *format, const struct tm *tp)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31 #if defined _WIN32 && ! defined __CYGWIN__
  32   /* Rectify the value of the environment variable TZ.
  33      There are four possible kinds of such values:
  34        - Traditional US time zone names, e.g. "PST8PDT".  Syntax: see
  35          <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset>
  36        - Time zone names based on geography, that contain one or more
  37          slashes, e.g. "Europe/Moscow".
  38        - Time zone names based on geography, without slashes, e.g.
  39          "Singapore".
  40        - Time zone names that contain explicit DST rules.  Syntax: see
  41          <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>
  42      The Microsoft CRT understands only the first kind.  It produces incorrect
  43      results if the value of TZ is of the other kinds.
  44      But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value
  45      of the second kind for most geographies, or of the first kind in a few
  46      other geographies.  If it is of the second kind, neutralize it.  For the
  47      Microsoft CRT, an absent or empty TZ means the time zone that the user
  48      has set in the Windows Control Panel.
  49      If the value of TZ is of the third or fourth kind -- Cygwin programs
  50      understand these syntaxes as well --, it does not matter whether we
  51      neutralize it or not, since these values occur only when a Cygwin user
  52      has set TZ explicitly; this case is 1. rare and 2. under the user's
  53      responsibility.  */
  54   const char *tz = getenv ("TZ");
  55   if (tz != NULL && strchr (tz, '/') != NULL)
  56     _putenv ("TZ=");
  57 #endif
  58 
  59   return wcsftime (buf, bufsize, format, tp);
  60 }

/* [previous][next][first][last][top][bottom][index][help] */