Module Name: src
Committed By: christos
Date: Sun Jan 21 16:55:56 UTC 2024
Modified Files:
src/bin/date: date.c
Log Message:
Handle -d %Y%m%d in the tools version. This is used in the release notes
Makefile.inc when BUILDID is specified. Consider providing parsedate(3)
in libcompat, but then we'd need yacc...
To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/bin/date/date.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/date/date.c
diff -u src/bin/date/date.c:1.65 src/bin/date/date.c:1.66
--- src/bin/date/date.c:1.65 Wed May 31 13:56:54 2023
+++ src/bin/date/date.c Sun Jan 21 11:55:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.65 2023/05/31 17:56:54 kim Exp $ */
+/* $NetBSD: date.c,v 1.66 2024/01/21 16:55:56 christos Exp $ */
/*
* Copyright (c) 1985, 1987, 1988, 1993
@@ -44,7 +44,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: date.c,v 1.65 2023/05/31 17:56:54 kim Exp $");
+__RCSID("$NetBSD: date.c,v 1.66 2024/01/21 16:55:56 christos Exp $");
#endif
#endif /* not lint */
@@ -98,8 +98,8 @@ main(int argc, char *argv[])
nflag = 1;
break;
case 'd':
-#ifndef HAVE_NBTOOL_CONFIG_H
rflag = 1;
+#ifndef HAVE_NBTOOL_CONFIG_H
tval = parsedate(optarg, NULL, NULL);
if (tval == -1) {
errx(EXIT_FAILURE,
@@ -107,6 +107,19 @@ main(int argc, char *argv[])
}
break;
#else
+ /* handle YYYYMMDD, or fail */
+ {
+ struct tm tm;
+ char *p;
+ memset(&tm, 0, sizeof(tm));
+ p = strptime(optarg, "%Y%m%d", &tm);
+ if (*p == '\0'
+ && tm.tm_year >= 0 && tm.tm_year < 1000
+ && tm.tm_mon >= 0 && tm.tm_mon <= 11
+ && tm.tm_mday >= 1 && tm.tm_mday <= 31
+ && (tval = mktime(&tm)) != -1)
+ break;
+ }
errx(EXIT_FAILURE,
"-d not supported in the tool version");
#endif