You are not logged in.
Pages: 1
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
Can you provide a minimal not working example?
Offline
#include <sys/stat.h>
Offline
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
Try putting those #defines before the include.
#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include <sys/stat.h>
Offline
why not use just the stat instead of stat64 ??
i rly dont know what this c program need to do i'm a beginner c/c++ programmer, but at least i can use google 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
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
Offline
@Cerebral: thanks, that did the trick! of course it does, I should have known that #defines only affect sources included AFTERWARDS...
@hbd: well I think I can google too 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
Last edited by lynix (2009-10-23 21:11:00)
Offline
Pages: 1