From 4c85ba73821e3ccea76c66391abf7ac7674b5d1b Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 21 Jan 2024 16:55:56 +0000 Subject: [PATCH] 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... --- bin/date/date.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/date/date.c b/bin/date/date.c index c51c748f1427..a622c429363d 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -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