Module Name: src Committed By: rillig Date: Sat Aug 19 19:59:17 UTC 2023
Modified Files: src/usr.bin/make: var.c Log Message: make: only work around wrong strftime if actually necessary The workaround is only needed if the time format contains '%s', in all other cases there is no need to preserve, set and restore the TZ environment variable. Suggested by sjg@. Only check for 's' in the format string, not for '%s', to allow for optional modifiers of the conversion specifier. To generate a diff of this commit: cvs rdiff -u -r1.1063 -r1.1064 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1063 src/usr.bin/make/var.c:1.1064 --- src/usr.bin/make/var.c:1.1063 Sat Aug 19 11:53:10 2023 +++ src/usr.bin/make/var.c Sat Aug 19 19:59:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1063 2023/08/19 11:53:10 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1064 2023/08/19 19:59:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1063 2023/08/19 11:53:10 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1064 2023/08/19 19:59:17 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -1886,8 +1886,8 @@ FormatTime(const char *fmt, time_t t, bo time(&t); if (*fmt == '\0') fmt = "%c"; - if (gmt) { - /* strftime only works with localtime, not with gmtime. */ + if (gmt && strchr(fmt, 's') != NULL) { + /* strftime "%s" only works with localtime, not with gmtime. */ const char *prev_tz_env = getenv("TZ"); char *prev_tz = prev_tz_env != NULL ? bmake_strdup(prev_tz_env) : NULL; @@ -1899,7 +1899,7 @@ FormatTime(const char *fmt, time_t t, bo } else unsetenv("TZ"); } else - strftime(buf, sizeof buf, fmt, localtime(&t)); + strftime(buf, sizeof buf, fmt, (gmt ? gmtime : localtime)(&t)); buf[sizeof buf - 1] = '\0'; return bmake_strdup(buf);