summaryrefslogtreecommitdiff
path: root/lib/strftime-fixes.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2017-04-30 17:14:35 +0200
committerBruno Haible <bruno@clisp.org>2017-04-30 19:26:38 +0200
commit9df4babee613569704bd8947de9a3cd46086b43e (patch)
treeee994ea3f1c88175c9be133bdbc134a7ee01464f /lib/strftime-fixes.c
parentdb1ee11e2168af7137db53289a92e306d2277b0b (diff)
downloadgnulib-9df4babee613569704bd8947de9a3cd46086b43e.tar.gz
strftime-fixes: New module.
* lib/time.in.h (strftime): New declaration. * lib/strftime-fixes.c: New file. * m4/strftime.m4 (gl_FUNC_GNU_STRFTIME): Inline gl_FUNC_STRFTIME macro. (gl_FUNC_STRFTIME): Remove macro. * m4/strftime-fixes.m4: New file. * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_STRFTIME, REPLACE_STRFTIME. * modules/time (Makefile.am): Substitute GNULIB_STRFTIME, REPLACE_STRFTIME. * modules/strftime-fixes: New file. * doc/posix-functions/strftime.texi: Mention the new module.
Diffstat (limited to 'lib/strftime-fixes.c')
-rw-r--r--lib/strftime-fixes.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/strftime-fixes.c b/lib/strftime-fixes.c
new file mode 100644
index 0000000000..6618c13491
--- /dev/null
+++ b/lib/strftime-fixes.c
@@ -0,0 +1,40 @@
+/* Work around platform bugs in strftime.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <time.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#undef strftime
+
+size_t
+rpl_strftime (char *buf, size_t bufsize, const char *format, const struct tm *tp)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* If the environment variable TZ has been set by Cygwin, neutralize it.
+ The Microsoft CRT interprets TZ differently than Cygwin and produces
+ incorrect results if TZ has the syntax used by Cygwin. */
+ const char *tz = getenv ("TZ");
+ if (tz != NULL && strchr (tz, '/') != NULL)
+ _putenv ("TZ=");
+#endif
+
+ return strftime (buf, bufsize, format, tp);
+}