[libc-commits] [libc] [libc] Change cookie_seek_function_t to take off_t argument (PR #223306)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Sun Sep 13 22:13:59 PDT 2026


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/223306

cookie_seek_function_t is defined as taking off_t rather than off64_t for offset argument in all C library implementations that support fopencookie.

>From 6f2314dc6c504df4e329b4ed61f6de0eb4154264 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Sun, 13 Sep 2026 22:09:36 -0700
Subject: [PATCH] [libc] Change cookie_seek_function_t to take off_t argument

cookie_seek_function_t is defined as taking off_t rather than off64_t
for offset argument in all C library implementations that support
fopencookie.
---
 libc/include/llvm-libc-types/CMakeLists.txt          | 4 ++--
 libc/include/llvm-libc-types/cookie_io_functions_t.h | 4 ++--
 libc/src/stdio/fopencookie.cpp                       | 5 ++---
 libc/test/src/stdio/CMakeLists.txt                   | 1 +
 libc/test/src/stdio/fopencookie_test.cpp             | 5 +++--
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 381098968d2ec..4c91bb656e456 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -34,6 +34,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
 endif()
 
+add_header(off_t HDR off_t.h)
 add_header(off64_t HDR off64_t.h)
 add_header(size_t HDR size_t.h)
 add_header(
@@ -68,7 +69,7 @@ add_header(cc_t HDR cc_t.h)
 add_header(clock_t HDR clock_t.h)
 add_header(clockid_t HDR clockid_t.h)
 add_header(cnd_t HDR cnd_t.h DEPENDS .__futex_word)
-add_header(cookie_io_functions_t HDR cookie_io_functions_t.h DEPENDS .off64_t .ssize_t)
+add_header(cookie_io_functions_t HDR cookie_io_functions_t.h DEPENDS .off_t .ssize_t)
 add_header(cpu_set_t HDR cpu_set_t.h)
 add_header(double_t HDR double_t.h)
 add_header(DIR HDR DIR.h)
@@ -132,7 +133,6 @@ add_header(nfds_t HDR nfds_t.h)
 add_header(nl_catd HDR nl_catd.h)
 add_header(nl_item HDR nl_item.h)
 add_header(nlink_t HDR nlink_t.h)
-add_header(off_t HDR off_t.h)
 add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
 add_header(posix_spawn_file_actions_t HDR posix_spawn_file_actions_t.h)
 add_header(posix_spawnattr_t HDR posix_spawnattr_t.h)
diff --git a/libc/include/llvm-libc-types/cookie_io_functions_t.h b/libc/include/llvm-libc-types/cookie_io_functions_t.h
index d1eea8ff3b5dc..27ad107c486b8 100644
--- a/libc/include/llvm-libc-types/cookie_io_functions_t.h
+++ b/libc/include/llvm-libc-types/cookie_io_functions_t.h
@@ -9,13 +9,13 @@
 #ifndef LLVM_LIBC_TYPES_COOKIE_IO_FUNCTIONS_T_H
 #define LLVM_LIBC_TYPES_COOKIE_IO_FUNCTIONS_T_H
 
-#include "off64_t.h"
+#include "off_t.h"
 #include "size_t.h"
 #include "ssize_t.h"
 
 typedef ssize_t cookie_read_function_t(void *, char *, size_t);
 typedef ssize_t cookie_write_function_t(void *, const char *, size_t);
-typedef int cookie_seek_function_t(void *, off64_t *, int);
+typedef int cookie_seek_function_t(void *, off_t *, int);
 typedef int cookie_close_function_t(void *);
 
 typedef struct {
diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp
index dafc7823e5fd9..5ff5fd097023e 100644
--- a/libc/src/stdio/fopencookie.cpp
+++ b/libc/src/stdio/fopencookie.cpp
@@ -61,10 +61,9 @@ ErrorOr<off_t> CookieFile::cookie_seek(File *f, off_t offset, int whence) {
   if (cookie_file->ops.seek == nullptr) {
     return Error(EINVAL);
   }
-  off64_t offset64 = offset;
-  int result = cookie_file->ops.seek(cookie_file->cookie, &offset64, whence);
+  int result = cookie_file->ops.seek(cookie_file->cookie, &offset, whence);
   if (result == 0)
-    return offset64;
+    return offset;
   return -1;
 }
 
diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index b25219ef3ca03..18d90f4913294 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -150,6 +150,7 @@ add_libc_test(
     fopencookie_test.cpp
   DEPENDS
     libc.include.stdio
+    libc.hdr.types.off_t
     libc.hdr.types.size_t
     libc.src.errno.errno
     libc.src.stdio.clearerr
diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp
index bcf5e674141a7..4c6dadd7ff70a 100644
--- a/libc/test/src/stdio/fopencookie_test.cpp
+++ b/libc/test/src/stdio/fopencookie_test.cpp
@@ -20,6 +20,7 @@
 #include "test/UnitTest/Test.h"
 
 #include "hdr/stdio_macros.h"
+#include "hdr/types/off_t.h"
 #include "hdr/types/size_t.h"
 #include "src/__support/libc_errno.h"
 
@@ -59,9 +60,9 @@ ssize_t read_ss(void *cookie, char *buf, size_t size) {
   return copysize;
 }
 
-int seek_ss(void *cookie, off64_t *offset, int whence) {
+int seek_ss(void *cookie, off_t *offset, int whence) {
   auto *ss = reinterpret_cast<StringStream *>(cookie);
-  off64_t new_offset;
+  off_t new_offset;
   if (whence == SEEK_SET) {
     new_offset = *offset;
   } else if (whence == SEEK_CUR) {



More information about the libc-commits mailing list