Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown error calling stat() against a 4 GB file on Windows

I have a 4 GB (exactly) file on an NTFS partition and a program that tries to get its size with stat() but it always fails with Unknown error (stat returns -1).

Does this mean that NTFS doesn't support 4 GB files? Or I have to use a different (Win32?) API?

Edit:

  struct stat st;
  if (stat(path.c_str(), &st) == -1) {
    printf("stat: %s\n", strerror(errno));
  }

outputs:

stat: Unknown error
like image 835
szx Avatar asked Nov 26 '25 16:11

szx


1 Answers

The stat function returns a stat struct that defines the file size with 32 bits, which means it can handle correctly file sizes only up to 4GB. You should use stat64.

See also the stat function family on MSDN

like image 162
Joni Avatar answered Nov 28 '25 16:11

Joni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!