[libc-commits] [libc] 5d20c85 - [libc] Change __llvm_libc_stdio_seek to match cookie_io_functions_t (#225632)
via libc-commits
libc-commits at lists.llvm.org
Thu Nov 19 00:50:21 PST 2026
Author: Petr Hosek
Date: 2026-11-19T00:50:16-08:00
New Revision: 5d20c85f4e1b8755b655bf1782b094fb35ec48d1
URL: https://github.com/llvm/llvm-project/commit/5d20c85f4e1b8755b655bf1782b094fb35ec48d1
DIFF: https://github.com/llvm/llvm-project/commit/5d20c85f4e1b8755b655bf1782b094fb35ec48d1.diff
LOG: [libc] Change __llvm_libc_stdio_seek to match cookie_io_functions_t (#225632)
This allows using __llvm_libc_stdio_seek directly without a need for an
adapter, matching the rest of the stdio embedding interface.
Added:
Modified:
libc/src/__support/OSUtil/baremetal/io.h
libc/src/stdio/baremetal/fseek.cpp
libc/src/stdio/baremetal/fseeko.cpp
libc/src/stdio/baremetal/ftell.cpp
libc/src/stdio/baremetal/ftello.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/OSUtil/baremetal/io.h b/libc/src/__support/OSUtil/baremetal/io.h
index 3a61fa8f4535ee..a24965500c7b71 100644
--- a/libc/src/__support/OSUtil/baremetal/io.h
+++ b/libc/src/__support/OSUtil/baremetal/io.h
@@ -57,11 +57,11 @@ extern "C" ssize_t __llvm_libc_stdio_read(void *cookie, char *buf, size_t size);
extern "C" ssize_t __llvm_libc_stdio_write(void *cookie, const char *buf,
size_t size);
-// Return the resulting absolute file position on success. On failure, return a
+// Update the `offset` to indicate the new stream offset. On failure, return a
// negative errno value.
-extern "C" off_t __llvm_libc_stdio_seek(void *cookie, off_t offset, int whence);
+extern "C" int __llvm_libc_stdio_seek(void *cookie, off_t *offset, int whence);
-// Return 0 on success or EOF on failure, matching fclose.
+// Return 0 on success or EOF on failure.
extern "C" int __llvm_libc_stdio_close(void *cookie);
void write_to_stderr(cpp::string_view msg);
diff --git a/libc/src/stdio/baremetal/fseek.cpp b/libc/src/stdio/baremetal/fseek.cpp
index 540c3cb70fbe55..533d3e1fe56fa7 100644
--- a/libc/src/stdio/baremetal/fseek.cpp
+++ b/libc/src/stdio/baremetal/fseek.cpp
@@ -26,10 +26,10 @@ LLVM_LIBC_FUNCTION(int, fseek, (::FILE * stream, long offset, int whence)) {
libc_errno = EINVAL;
return -1;
}
- off_t result =
- __llvm_libc_stdio_seek(stream, static_cast<off_t>(offset), whence);
+ off_t off = offset;
+ int result = __llvm_libc_stdio_seek(stream, &off, whence);
if (result < 0) {
- libc_errno = static_cast<int>(-result);
+ libc_errno = -result;
return -1;
}
return 0;
diff --git a/libc/src/stdio/baremetal/fseeko.cpp b/libc/src/stdio/baremetal/fseeko.cpp
index 42c87aebe6911c..eb6c0358c37648 100644
--- a/libc/src/stdio/baremetal/fseeko.cpp
+++ b/libc/src/stdio/baremetal/fseeko.cpp
@@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, fseeko, (::FILE * stream, off_t offset, int whence)) {
libc_errno = EINVAL;
return -1;
}
- off_t result = __llvm_libc_stdio_seek(stream, offset, whence);
+ int result = __llvm_libc_stdio_seek(stream, &offset, whence);
if (result < 0) {
libc_errno = static_cast<int>(-result);
return -1;
diff --git a/libc/src/stdio/baremetal/ftell.cpp b/libc/src/stdio/baremetal/ftell.cpp
index 8b062d955a4f30..ac2a6106d38e81 100644
--- a/libc/src/stdio/baremetal/ftell.cpp
+++ b/libc/src/stdio/baremetal/ftell.cpp
@@ -27,12 +27,13 @@ LLVM_LIBC_FUNCTION(long, ftell, (::FILE * stream)) {
libc_errno = EINVAL;
return -1;
}
- off_t result = __llvm_libc_stdio_seek(stream, 0, SEEK_CUR);
+ off_t offset = 0;
+ int result = __llvm_libc_stdio_seek(stream, &offset, SEEK_CUR);
if (result < 0) {
libc_errno = static_cast<int>(-result);
return -1;
}
- return static_cast<long>(result);
+ return static_cast<long>(offset);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/ftello.cpp b/libc/src/stdio/baremetal/ftello.cpp
index 0f5db4872a1128..be861414d4efc9 100644
--- a/libc/src/stdio/baremetal/ftello.cpp
+++ b/libc/src/stdio/baremetal/ftello.cpp
@@ -27,12 +27,13 @@ LLVM_LIBC_FUNCTION(off_t, ftello, (::FILE * stream)) {
libc_errno = EINVAL;
return static_cast<off_t>(-1);
}
- off_t result = __llvm_libc_stdio_seek(stream, 0, SEEK_CUR);
+ off_t offset = 0;
+ int result = __llvm_libc_stdio_seek(stream, &offset, SEEK_CUR);
if (result < 0) {
libc_errno = static_cast<int>(-result);
return static_cast<off_t>(-1);
}
- return result;
+ return offset;
}
} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list