summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-10-15 18:53:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-10-15 18:54:49 -0700
commit074cbe590bb5f9d4be7334162e0803264bf5717d (patch)
tree0c95c04744c2321bcc0108f67c9eaa6c784681de /src
parent08b103ff4da9be30ea90e5a04b4ccea694f18ed3 (diff)
downloaddiffutils-074cbe590bb5f9d4be7334162e0803264bf5717d.tar.gz
diff: fix timezone bug on Solaris
Problem reported by Vladimir Marek (bug#51228). * NEWS: Mention this. * src/context.c (print_context_label): Pass localtz to nstrftime, instead of always passing 0. * src/diff.c (main) [!HAVE_TM_GMTOFF]: Initialize localtz if time_format uses %z. * src/diff.h (localtz): New decl. * tests/Makefile.am (TESTS): Add timezone. * tests/timezone: New test.
Diffstat (limited to 'src')
-rw-r--r--src/context.c2
-rw-r--r--src/diff.c3
-rw-r--r--src/diff.h7
3 files changed, 11 insertions, 1 deletions
diff --git a/src/context.c b/src/context.c
index b3cfa7d..adcfdb3 100644
--- a/src/context.c
+++ b/src/context.c
@@ -52,7 +52,7 @@ print_context_label (char const *mark,
INT_STRLEN_BOUND (time_t) + 11)];
struct tm const *tm = localtime (&inf->stat.st_mtime);
int nsec = get_stat_mtime_ns (&inf->stat);
- if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, 0, nsec)))
+ if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, localtz, nsec)))
{
verify (TYPE_IS_INTEGER (time_t));
if (LONG_MIN <= TYPE_MINIMUM (time_t)
diff --git a/src/diff.c b/src/diff.c
index fedc7df..0961afb 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -729,6 +729,9 @@ main (int argc, char **argv)
#else
time_format = "%Y-%m-%d %H:%M:%S %z";
#endif
+#if !HAVE_TM_GMTOFF
+ localtz = tzalloc (getenv ("TZ"));
+#endif
}
else
{
diff --git a/src/diff.h b/src/diff.h
index d65c1da..34caa37 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -155,6 +155,13 @@ XTERN bool ignore_file_name_case;
(--no-dereference). */
XTERN bool no_dereference_symlinks;
+/* Local timezone for 'c' output headers, if needed. */
+#if HAVE_TM_GMTOFF
+# define localtz 0 /* Placeholder since localtz is never needed. */
+#else
+XTERN timezone_t localtz;
+#endif
+
/* File labels for '-c' output headers (--label). */
XTERN char *file_label[2];