[PATCH 11/59] tzset no longer calls ftello
Paul Eggert
eggert@cs.ucla.edu
Sun Jan 5 05:56:46 GMT 2025
* time/tzfile.c (__tzfile_read): Compute file offset directly
rather than invoking ftello.
---
time/tzfile.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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
--
2.45.2
More information about the Libc-alpha
mailing list