Skip to content

Commit 2739c3c

Browse files
committed
[libcxx] Use _ftelli64/_fseeki64 on Windows
This allows using the full 64 bit range for file offsets. This should fix the issue reported downstream at mstorsjo/llvm-mingw#462.
1 parent 5a34e6f commit 2739c3c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

libcxx/include/fstream

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,11 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
936936
default:
937937
return pos_type(off_type(-1));
938938
}
939-
# if !_LIBCPP_HAS_OFF_T_FUNCTIONS
939+
# if defined(_LIBCPP_MSVCRT_LIKE)
940+
if (_fseeki64(__file_, __width > 0 ? __width * __off : 0, __whence))
941+
return pos_type(off_type(-1));
942+
pos_type __r = _ftelli64(__file_);
943+
# elif !_LIBCPP_HAS_OFF_T_FUNCTIONS
940944
if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
941945
return pos_type(off_type(-1));
942946
pos_type __r = ftell(__file_);
@@ -954,7 +958,10 @@ typename basic_filebuf<_CharT, _Traits>::pos_type
954958
basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) {
955959
if (__file_ == nullptr || sync())
956960
return pos_type(off_type(-1));
957-
# if !_LIBCPP_HAS_OFF_T_FUNCTIONS
961+
# if defined(_LIBCPP_MSVCRT_LIKE)
962+
if (_fseeki64(__file_, __sp, SEEK_SET))
963+
return pos_type(off_type(-1));
964+
# elif !_LIBCPP_HAS_OFF_T_FUNCTIONS
958965
if (fseek(__file_, __sp, SEEK_SET))
959966
return pos_type(off_type(-1));
960967
# else

libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/offset_range.pass.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
// Test that we can seek using offsets larger than 32 bit, and that we can
1212
// retrieve file offsets larger than 32 bit.
1313

14-
// On MSVC targets, we only use the 32 bit fseek/ftell functions. For MinGW
15-
// targets, we use fseeko/ftello, but the user needs to define
16-
// _FILE_OFFSET_BITS=64 to make them 64 bit.
17-
//
18-
// XFAIL: target={{.*}}-windows{{.*}}
19-
2014
// On 32 bit Android platforms, off_t is 32 bit by default. By defining
2115
// _FILE_OFFSET_BITS=64, one gets a 64 bit off_t, but the corresponding
2216
// 64 bit ftello/fseeko functions are only available since Android API 24 (7.0).

0 commit comments

Comments
 (0)