Skip to content

Commit

Permalink
[libcxx] Use _ftelli64/_fseeki64 on Windows
Browse files Browse the repository at this point in the history
This allows using the full 64 bit range for file offsets.

This should fix the issue reported downstream at
mstorsjo/llvm-mingw#462.
  • Loading branch information
mstorsjo committed Jan 29, 2025
1 parent 5a34e6f commit 2739c3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 9 additions & 2 deletions libcxx/include/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,11 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
default:
return pos_type(off_type(-1));
}
# if !_LIBCPP_HAS_OFF_T_FUNCTIONS
# if defined(_LIBCPP_MSVCRT_LIKE)
if (_fseeki64(__file_, __width > 0 ? __width * __off : 0, __whence))
return pos_type(off_type(-1));
pos_type __r = _ftelli64(__file_);
# elif !_LIBCPP_HAS_OFF_T_FUNCTIONS
if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
return pos_type(off_type(-1));
pos_type __r = ftell(__file_);
Expand All @@ -954,7 +958,10 @@ typename basic_filebuf<_CharT, _Traits>::pos_type
basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) {
if (__file_ == nullptr || sync())
return pos_type(off_type(-1));
# if !_LIBCPP_HAS_OFF_T_FUNCTIONS
# if defined(_LIBCPP_MSVCRT_LIKE)
if (_fseeki64(__file_, __sp, SEEK_SET))
return pos_type(off_type(-1));
# elif !_LIBCPP_HAS_OFF_T_FUNCTIONS
if (fseek(__file_, __sp, SEEK_SET))
return pos_type(off_type(-1));
# else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
// Test that we can seek using offsets larger than 32 bit, and that we can
// retrieve file offsets larger than 32 bit.

// On MSVC targets, we only use the 32 bit fseek/ftell functions. For MinGW
// targets, we use fseeko/ftello, but the user needs to define
// _FILE_OFFSET_BITS=64 to make them 64 bit.
//
// XFAIL: target={{.*}}-windows{{.*}}

// On 32 bit Android platforms, off_t is 32 bit by default. By defining
// _FILE_OFFSET_BITS=64, one gets a 64 bit off_t, but the corresponding
// 64 bit ftello/fseeko functions are only available since Android API 24 (7.0).
Expand Down

0 comments on commit 2739c3c

Please sign in to comment.