[11/59] tzset no longer calls ftello

Message ID 20250105055750.1668721-12-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:56 a.m. UTC
  * time/tzfile.c (__tzfile_read): Compute file offset directly
rather than invoking ftello.
---
 time/tzfile.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/time/tzfile.c b/time/tzfile.c
index 9d5f428f47..15d1890892 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -168,6 +168,7 @@  __tzfile_read (const char *file)
   f = fopen (file, "rce");
   if (f == NULL)
     goto ret_free_transitions;
+  off_t f_offset = 0;
 
   /* Get information about the file we are actually using.  */
   if (__fstat64_time64 (__fileno (f), &st) != 0)
@@ -190,6 +191,7 @@  __tzfile_read (const char *file)
       || memcmp (tzhead.tzh_magic, TZ_MAGIC, sizeof (tzhead.tzh_magic)) != 0)
     goto lose;
 
+  f_offset += sizeof tzhead;
   num_transitions = (size_t) decode (tzhead.tzh_timecnt);
   num_types = (size_t) decode (tzhead.tzh_typecnt);
   chars = (size_t) decode (tzhead.tzh_charcnt);
@@ -215,6 +217,7 @@  __tzfile_read (const char *file)
       if (fseek (f, to_skip, SEEK_CUR) != 0)
 	goto lose;
 
+      f_offset += to_skip;
       goto read_again;
     }
 
@@ -223,7 +226,7 @@  __tzfile_read (const char *file)
   size_t tzspec_len;
   if (trans_width == 8)
     {
-      off_t rem = st.st_size - __ftello (f);
+      off_t rem = st.st_size - f_offset;
       if (__builtin_expect (rem < 0
 			    || (size_t) rem < (num_transitions * (8 + 1)
 					       + num_types * 6