From: Alejandro Colomar Date: Tue, 18 Feb 2025 14:38:35 +0000 (+0100) Subject: lib/: Move get_date() to lib/strtoday.c X-Git-Tag: 4.18.0-rc1~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aee6797834d3746138afa441544689d95139892a;p=thirdparty%2Fshadow.git lib/: Move get_date() to lib/strtoday.c Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index e6a2cf2df..04e6c251c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -104,8 +104,6 @@ libshadow_la_SOURCES = \ fs/readlink/readlinknul.c \ fs/readlink/readlinknul.h \ get_pid.c \ - getdate.c \ - getdate.h \ getdef.c \ getdef.h \ getgr_nam_gid.c \ diff --git a/lib/getdate.c b/lib/getdate.c deleted file mode 100644 index cc2c3f155..000000000 --- a/lib/getdate.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: 2025, Alejandro Colomar -// SPDX-FileCopyrightText: 2025, "Haelwenn (lanodan) Monnier" -// SPDX-License-Identifier: BSD-3-Clause - - -#include - -#include -#include - -#include "getdate.h" -#include "string/strcmp/streq.h" - - -time_t -get_date(const char *s) -{ - time_t t; - struct tm tm; - const char *p; - - t = 0; - if (gmtime_r(&t, &tm) == NULL) - return -1; - - p = strptime(s, "%Y-%m-%d", &tm); - if (p == NULL || !streq(p, "")) - return -1; - - return timegm(&tm); -} diff --git a/lib/getdate.h b/lib/getdate.h deleted file mode 100644 index 734855921..000000000 --- a/lib/getdate.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1997 - 2000, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _GETDATE_H_ -#define _GETDATE_H_ - -#include -#include "defines.h" - -time_t get_date(const char *s); -#endif diff --git a/lib/strtoday.c b/lib/strtoday.c index 6e0e55c70..ea327faee 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -1,22 +1,26 @@ -/* - * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1999, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1999, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008, Nicolas François +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-FileCopyrightText: 2025, "Haelwenn (lanodan) Monnier" +// SPDX-License-Identifier: BSD-3-Clause + #include -#include +#include +#include #include "atoi/str2i.h" -#include "getdate.h" +#include "defines.h" #include "prototypes.h" #include "string/strcmp/streq.h" +static time_t get_date(const char *s); + + // string parse-to day-since-Epoch long strtoday(const char *str) @@ -39,3 +43,22 @@ strtoday(const char *str) } return t / DAY; } + + +static time_t +get_date(const char *s) +{ + time_t t; + struct tm tm; + const char *p; + + t = 0; + if (gmtime_r(&t, &tm) == NULL) + return -1; + + p = strptime(s, "%Y-%m-%d", &tm); + if (p == NULL || !streq(p, "")) + return -1; + + return timegm(&tm); +}