From 3e602b58a2aa581aedbe3d6516ebea4bd233b97b Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 27 Dec 2021 20:50:06 +0100 Subject: [PATCH] Remove HAVE_STRFTIME ifdefs strftime(3) has been in standard C since C89. It is also in POSIX.1-2001, and in SVr4 (see strftime(3) and strftime(3p)). We can assume that this function is always available. Signed-off-by: Alejandro Colomar --- configure.ac | 1 - libmisc/failure.c | 25 ------------------------- src/chage.c | 15 --------------- src/faillog.c | 7 +------ src/lastlog.c | 8 -------- src/login.c | 7 +------ 6 files changed, 2 insertions(+), 61 deletions(-) diff --git a/configure.ac b/configure.ac index a94e897f..bfabcd38 100644 --- a/configure.ac +++ b/configure.ac @@ -115,7 +115,6 @@ dnl Checks for library functions. AC_TYPE_GETGROUPS AC_TYPE_SIGNAL AC_FUNC_UTIME_NULL -AC_FUNC_STRFTIME AC_REPLACE_FUNCS(mkdir putgrent putpwent putspent rename rmdir) AC_REPLACE_FUNCS(sgetgrent sgetpwent sgetspent) AC_REPLACE_FUNCS(snprintf strcasecmp strdup strerror strstr) diff --git a/libmisc/failure.c b/libmisc/failure.c index a1f3ec79..6234647f 100644 --- a/libmisc/failure.c +++ b/libmisc/failure.c @@ -232,13 +232,8 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) void failprint (const struct faillog *fail) { struct tm *tp; - -#if HAVE_STRFTIME char lasttimeb[256]; char *lasttime = lasttimeb; -#else - char *lasttime; -#endif time_t NOW; if (0 == fail->fail_cnt) { @@ -248,31 +243,11 @@ void failprint (const struct faillog *fail) tp = localtime (&(fail->fail_time)); (void) time (&NOW); -#if HAVE_STRFTIME /* * Print all information we have. */ (void) strftime (lasttimeb, sizeof lasttimeb, "%c", tp); -#else - /* - * Do the same thing, but don't use strftime since it - * probably doesn't exist on this system - */ - lasttime = asctime (tp); - lasttime[24] = '\0'; - - if ((NOW - fail->fail_time) < YEAR) { - lasttime[19] = '\0'; - } - if ((NOW - fail->fail_time) < DAY) { - lasttime = lasttime + 11; - } - - if (' ' == *lasttime) { - lasttime++; - } -#endif /*@-formatconst@*/ (void) printf (ngettext ("%d failure since last login.\n" "Last was %s on %s.\n", diff --git a/src/chage.c b/src/chage.c index 5dfc68e8..02b7ac3e 100644 --- a/src/chage.c +++ b/src/chage.c @@ -244,7 +244,6 @@ static int new_fields (void) static void print_date (time_t date) { -#ifdef HAVE_STRFTIME struct tm *tp; char buf[80]; char format[80]; @@ -263,20 +262,6 @@ static void print_date (time_t date) (void) strftime (buf, sizeof buf, format, tp); (void) puts (buf); } -#else - struct tm *tp; - char *cp = NULL; - - tp = gmtime (&date); - if (NULL != tp) { - cp = asctime (tp); - } - if (NULL != cp) { - (void) printf ("%6.6s, %4.4s\n", cp + 4, cp + 20); - } else { - (void) printf ("time_t: %lu\n", date); - } -#endif } /* diff --git a/src/faillog.c b/src/faillog.c index db4fc72b..826dbf29 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -111,11 +111,8 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force) off_t offset; struct faillog fl; time_t now; - -#ifdef HAVE_STRFTIME char *cp; char ptime[80]; -#endif if (NULL == pw) { return; @@ -168,13 +165,11 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force) fprintf (stderr, "Cannot read time from faillog.\n"); return; } -#ifdef HAVE_STRFTIME strftime (ptime, sizeof (ptime), "%D %H:%M:%S %z", tm); cp = ptime; -#endif + printf ("%-9s %5d %5d ", pw->pw_name, fl.fail_cnt, fl.fail_max); - /* FIXME: cp is not defined ifndef HAVE_STRFTIME */ printf ("%s %s", cp, fl.fail_line); if (0 != fl.fail_locktime) { if ( ((fl.fail_time + fl.fail_locktime) > now) diff --git a/src/lastlog.c b/src/lastlog.c index b3a152d9..b9a9c5a9 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -108,10 +108,7 @@ static void print_one (/*@null@*/const struct passwd *pw) time_t ll_time; off_t offset; struct lastlog ll; - -#ifdef HAVE_STRFTIME char ptime[80]; -#endif #ifdef HAVE_LL_HOST int maxIPv6Addrlen; @@ -177,13 +174,8 @@ static void print_one (/*@null@*/const struct passwd *pw) ll_time = ll.ll_time; tm = localtime (&ll_time); -#ifdef HAVE_STRFTIME strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm); cp = ptime; -#else - cp = asctime (tm); - cp[24] = '\0'; -#endif if (ll.ll_time == (time_t) 0) { cp = _("**Never logged in**\0"); diff --git a/src/login.c b/src/login.c index 1623f29d..f30a42ec 100644 --- a/src/login.c +++ b/src/login.c @@ -534,7 +534,7 @@ int main (int argc, char **argv) #ifdef RLOGIN char term[128] = ""; #endif /* RLOGIN */ -#if defined(HAVE_STRFTIME) && !defined(USE_PAM) +#if !defined(USE_PAM) char ptime[80]; #endif unsigned int delay; @@ -1321,16 +1321,11 @@ int main (int argc, char **argv) && (ll.ll_time != 0)) { time_t ll_time = ll.ll_time; -#ifdef HAVE_STRFTIME (void) strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", localtime (&ll_time)); printf (_("Last login: %s on %s"), ptime, ll.ll_line); -#else - printf (_("Last login: %.19s on %s"), - ctime (&ll_time), ll.ll_line); -#endif #ifdef HAVE_LL_HOST /* __linux__ || SUN4 */ if ('\0' != ll.ll_host[0]) { printf (_(" from %.*s"),