[42/59] __offtime now returns struct tm *

Message ID 20250105055750.1668721-43-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:57 a.m. UTC
  * time/offtime.c (__offtime): Refactor by returning struct tm *
instead of int.  All callers changed.
---
 include/time.h | 8 ++++----
 time/offtime.c | 8 ++++----
 time/tzfile.c  | 2 +-
 time/tzset.c   | 7 +++----
 4 files changed, 12 insertions(+), 13 deletions(-)
  

Patch

diff --git a/include/time.h b/include/time.h
index e9c083646a..186ea657cb 100644
--- a/include/time.h
+++ b/include/time.h
@@ -250,10 +250,10 @@  libc_hidden_proto (__gettimeofday64)
 /* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
-   Return nonzero if successful.  */
-extern int __offtime (__time64_t __timer,
-		      long int __offset,
-		      struct tm *__tp) attribute_hidden;
+   Return TP if successful, a null pointer otherwise.  */
+extern struct tm *__offtime (__time64_t __timer,
+			     long int __offset,
+			     struct tm *__tp) attribute_hidden;
 
 extern char *__asctime_r (const struct tm *__tp, char *__buf)
   attribute_hidden;
diff --git a/time/offtime.c b/time/offtime.c
index c94573e931..89cdcc4b15 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -24,8 +24,8 @@ 
 /* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
-   Return nonzero if successful.  */
-int
+   Return TP if successful, a null pointer otherwise.  */
+struct tm *
 __offtime (__time64_t t, long int offset, struct tm *tp)
 {
   __time64_t days, rem, y;
@@ -73,7 +73,7 @@  __offtime (__time64_t t, long int offset, struct tm *tp)
     {
       /* The year cannot be represented due to overflow.  */
       __set_errno (EOVERFLOW);
-      return 0;
+      return NULL;
     }
   tp->tm_yday = days;
   ip = __mon_yday[__isleap(y)];
@@ -82,5 +82,5 @@  __offtime (__time64_t t, long int offset, struct tm *tp)
   days -= ip[y];
   tp->tm_mon = y;
   tp->tm_mday = days + 1;
-  return 1;
+  return tp;
 }
diff --git a/time/tzfile.c b/time/tzfile.c
index 3ca08d16d4..9c05811e22 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -648,7 +648,7 @@  __tzfile_compute (__time64_t timer, int use_localtime,
 
 	  /* Convert to broken down structure.  If this fails do not
 	     use the string.  */
-	  if (__glibc_unlikely (! __offtime (timer, 0, tp)))
+	  if (__glibc_unlikely (__offtime (timer, 0, tp) == NULL))
 	    goto use_last;
 
 	  /* Use the rules from the TZ string to compute the change.  */
diff --git a/time/tzset.c b/time/tzset.c
index 90ecdf4210..671394f02d 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -610,9 +610,8 @@  __tz_convert (__time64_t timer, int use_localtime, struct tm *tp)
 		      &leap_extra_sec, tp);
   else
     {
-      if (! __offtime (timer, 0, tp))
-	tp = NULL;
-      else if (use_localtime)
+      tp = __offtime (timer, 0, tp);
+      if (tp && use_localtime)
 	__tz_compute (timer, tp);
       leap_correction = 0;
       leap_extra_sec = false;
@@ -627,7 +626,7 @@  __tz_convert (__time64_t timer, int use_localtime, struct tm *tp)
 	  tp->tm_gmtoff = 0L;
 	}
 
-      if (__offtime (timer, tp->tm_gmtoff - leap_correction, tp))
+      if (__offtime (timer, tp->tm_gmtoff - leap_correction, tp) != NULL)
 	{
 	  /* This assumes leap seconds can occur only when the local
 	     time offset from UTC is a multiple of 60 seconds,