What is the best way to find the past 2GiB in C?

There seem to be many different ways to search in C:

  • fseek()
  • fsetpos()
  • fseeko()
  • lseek()

And many seem to have versions *64():

  • fseeko64()
  • lseek64()

To complicate matters, many of them appear to require macro definitions (such as _LARGEFILE64_SOURCEor _GNU_SOURCE) or to use 64-bit versions.

What is the easiest way to guarantee 64-bit I / O using ANSI C on Windows, Linux, Mac, BSD, Solaris, etc., and since when is it supported by every OS?

+4
source share
2 answers

For the code to work, you must use at least one of the following restrictions:

  • long- 64-bit +, then use fseek().

  • , , fread(), fgets(), fscanf(), fgets(), fgetpos(), fsetpos(). , .

  • 64- , , lseek64().

  • 32- fseek().

  • rewind() fgetc()/fread().

+1

64- - ANSI C on Windows, Linux, Mac, BSD, Solaris ..

? 64- . , . size_t , unsigned int - size_t - size_t. , , ANSI C, C89 , , 64- .

, C, , 2 . 64- POSIX- IO (open(), read(), write() ..) size_t/ssize_t, POSIX IO 64-. POSIX fseeko() ftello(), 64- .

, ?

. . , "" 64- :

  • Solaris: 1998
  • Linux: 2003
  • Windows: 2006
  • OS X: 2007
0

Source: https://habr.com/ru/post/1621043/


All Articles