[libcxx-commits] [libcxx] [libc++] Support file offsets larger than 2GB in basic_filebuf on 32-bit AIX and 32-bit glibc Linux (PR #215892)
Hubert Tong via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 14 07:52:51 PDT 2026
================
@@ -217,6 +217,20 @@ typedef basic_fstream<wchar_t> wfstream;
# pragma GCC system_header
# endif
+# if defined(_AIX) || (defined(__linux__) && defined(__GLIBC__))
+# define _LIBCPP_HAS_LARGEFILE_API 1
+# else
+# define _LIBCPP_HAS_LARGEFILE_API 0
+# endif
+
+# if _LIBCPP_HAS_LARGEFILE_API
+// On AIX and glibc on Linux, fopen64/fseeko64/ftello64 are not guaranteed to always be declared, so we declare them
+// here. They are not POSIX-reserved names, so we use __asm__ to guard them against a user #define.
+extern "C" FILE* __libcpp_fopen64(const char*, const char*) __asm__("fopen64");
+extern "C" long long __libcpp_ftello64(FILE*) __asm__("ftello64");
+extern "C" int __libcpp_fseeko64(FILE*, long long, int) __asm__("fseeko64");
+# endif
----------------
hubert-reinterpretcast wrote:
Adding declarations that we can use for the APIs is not really avoidable for AIX because the strategy of some porting efforts to AIX (including for C++ code that would be used with libc++) make use of "clean", non-namespace polluting configurations of the system headers (to avoid conflicts). Such header configurations do not declare these non-reserved names.
@philnik777, would you prefer if these were simply of the non-reserved names (opening the source to conflicts with user macros or declarations—say of something reasonable like a file-scope static variable that is a function pointer)? That way, at least the call sites between the glibc and the AIX cases can be common.
https://github.com/llvm/llvm-project/pull/215892
More information about the libcxx-commits
mailing list