You are not logged in.

#1 2009-10-23 07:56:15

lynix
Member
From: Karlsruhe, Germany
Registered: 2008-04-23
Posts: 230

[solved] stat64() usage in C

Can someone tell me how to use the large file functions, especially stat64()? I always get

warning: implicit declaration of function 'stat64'

and for the struct stat64 named "filestat"

error: storage size of 'filestat' isn't known

I already crawled every page I found via google and tried with no success:

- compiling with -D_FILE_OFFSET_BITS=64
- #define __USE_LARGEFILE64
- #define _LARGEFILE_SOURCE
- #define _LARGEFILE64_SOURCE

Any suggestions? Thanks in advance!


lynix

Last edited by lynix (2009-10-23 21:11:22)

Offline

#2 2009-10-23 12:31:13

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: [solved] stat64() usage in C

Can you provide a minimal not working example?

Offline

#3 2009-10-23 18:21:43

meth0dz
Member
Registered: 2009-10-15
Posts: 8

Re: [solved] stat64() usage in C

#include <sys/stat.h>

Offline

#4 2009-10-23 20:25:25

lynix
Member
From: Karlsruhe, Germany
Registered: 2008-04-23
Posts: 230

Re: [solved] stat64() usage in C

Thanks for the replies. Here is a minimal example, named test.c:

#include <sys/stat.h>

#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

int main()
{
    struct stat64 mystat;

    stat64("/etc/fstab", &mystat);

    return 0;
}

which gives

test.c: In function 'main':
test.c:9: error: storage size of 'mystat' isn't known

lynix

Offline

#5 2009-10-23 20:47:28

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: [solved] stat64() usage in C

Try putting those #defines before the include.

#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

#include <sys/stat.h>

Offline

#6 2009-10-23 21:03:24

hBd
Member
From: Romania - Cluj Napoca
Registered: 2008-06-08
Posts: 241
Website

Re: [solved] stat64() usage in C

why not use just the stat instead of stat64 ??
i rly dont know what this c program need to do smile i'm a beginner c/c++ programmer, but at least i can use google tongue and i found that use stat instead of stat64...
and i tried to and compiles without a problem, so i think it need to be good smile

  1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  test.c
  5  *
  6  *    Description:  
  7  *
  8  *        Version:  1.0
  9  *        Created:  10/23/2009 11:52:20 PM
 10  *       Revision:  none
 11  *       Compiler:  gcc
 12  *
 13  *         Author:  Czaka Hunor (), czhunor@gmail.com
 14  *        Company:  
 15  *
 16  * =====================================================================================
 17  */
 18 
 19 #include <sys/stat.h>
 20 
 21 #define __USE_LARGEFILE64
 22 #define _LARGEFILE_SOURCE
 23 #define _LARGEFILE64_SOURCE
 24 
 25 int main()
 26 {
 27     struct stat mystat;
 28     
 29     stat("/etc/fstab", &mystat);
 30     
 31     return 0;
 32 }
┌─[ hybrid@arch ~ ]
└─[ $> gcc -Wall -c test.c 
test.c: In function 'main':
test.c:27: error: storage size of 'mystat' isn't known
test.c:29: warning: implicit declaration of function '_stat64'
test.c:27: warning: unused variable 'mystat'
┌─[ hybrid@arch ~ ]
└─[ $> gcc -Wall -c test.c 
┌─[ hybrid@arch ~ ]
└─[ $> gcc test.o -o test
┌─[ hybrid@arch ~ ]
└─[ $> ./test 
┌─[ hybrid@arch ~ ]
└─[ $>

hope i helped smile

Offline

#7 2009-10-23 21:10:18

lynix
Member
From: Karlsruhe, Germany
Registered: 2008-04-23
Posts: 230

Re: [solved] stat64() usage in C

@Cerebral: thanks, that did the trick! smile of course it does, I should have known that #defines only affect sources included AFTERWARDS...

@hbd: well I think I can google too wink  What you suggest works fine for files smaller than 2G. With bigger ones it fails on i686 because the struct that stat() writes to can't handle the big filesize to be stored in st_size.

Thanks @ you all smile

Last edited by lynix (2009-10-23 21:11:00)

Offline

Board footer

Powered by FluxBB