Alternatives to fseeko for Cygwin?

1.3k views Asked by At

I have installed Cygwin (CYGWIN_NT-6.1 AlexReynolds-PC 1.7.27(0.271/5/3) 2013-12-09 11:54 x86_64 Cygwin) and GNU gcc/g++ 4.8.1.

I am compiling some tools that use POSIX C I/O routines, such as fseeko() and get a fatal error of the following sort:

 error: ‘fseeko’ was not declared in this scope
     int retValue = fseeko(stream, offset, whence);

Is fseeko() available in GNU gcc/g++ 4.8.1 on Cygwin? Are alternatives available which reliably honor a 64-bit offset, if not?

3

There are 3 answers

0
rr- On

In my case the error was because I compiled the program with --std=c++11. Changing it to --std=gnu++11 fixed the problem with compilation, but now I wonder if I should be using fseeko at all.

Then I peeked at Cygwin's /usr/include/stdio.h and discovered the same thing as in this discussion. There is an interesting reply:

On Oct 29 14:32, Hongliang Wang wrote:

Hello all,

My platform is WindowsXP+SP2, Cygwin DLL release version is 1.5.24-2

I am trying to make my program support large files, so in stdio.h I found

356 #ifdef __LARGE64_FILES
357 #if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)

However, when I tried to compile with _COMPILING_NEWLIB, it fails

Never do that. It should only be set when compiling newlib itself.

$ gcc -Wall -D_COMPILING_NEWLIB test.c -o test
/cygdrive/c/DOCUME~1/wan/LOCALS~1/Temp/ccUmErSH.o:test.c:(.text+0x3a):
undefined reference to `_fopen64'
collect2: ld returned 1 exit status

It seems as if fopen64 is mapped to _fopen64, while the latter is missing.

Could anybody tell me how to compile with _COMPILING_NEWLIB flag or how does Cygwin support large files?

Don't compile with _COMPILING_NEWLIB. 64 bit file access is the natural file access type for Cygwin. off_t is 8 bytes. There are no foo64 functions for that reason. Just use fopen and friends and you get 64 bit file access for free.

Corinna

-- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat

So there you have it.

1
Guntram Blohm On

Just use fseek. As long as your long's are 64 bit, there's no difference.

2
Adam Rosenfield On

fseeko() is available on my install of Cygwin (CYGWIN_NT-6.1-WOW64 1.7.25(0.270/5/3) 2013-08-31 20:39 i686 Cygwin) with GCC 4.7.3. But if your install doesn't have it for some reason, you have a couple of alternatives:

  • fseek(), with the caveat that the offset is likely limited to 32 bits instead of 64 (depending on sizeof(long))
  • fsetpos(), which takes an fpos_t for the offset. However, fpos_t may be an opaque structure, so the only reliable way to use it is by calling fgetpos() to get the current position and then later call fsetpos() to restore the offset to the earlier position; you can't use it to seek to a particular offset otherwise.