On 9/22/25 18:46, Vladimir Dergachev wrote:

Just wanted to share something I just run into and fixed - when an R package is compiled for 64-bit Windows using "ucrt" C library, functions like ftell() and fseek() use 32-bit arguments for offsets, rather than 64-bit.

What's worse the type "off_t" is 32-bit as well, which defeats the purpose of introducing off_t in the first place.

The solution for me was to replace ftell()/fseek() with MS-specific _lseeki64(), _ftelli64() and _fseeki64(), and redefine off_t to be 64-bit
"long long int".

So typical MS - there is a C-library to compile against but without changes the code only works up to 2GB.

It might be a good idea to have an R-shim to isolate ucrt() and provide 64-bit functions for R packages.

I think this is something mingw-w64 should take care off, and having a quick look at the sources it seems it probably does.

I would start from the POSIX specification and then check how much of it is supported by mingw-w64, perhaps using _FILE_OFFSET_BITS and lseek(), ftello(), fseeko() would work.

Best
Tomas



What do you think?

best

Vladimir Dergachev

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to