试试这个?
$ cat a.c
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
printf("sizeof(off_t) = %d
", sizeof(off_t));
int fd = open("test", O_WRONLY | O_CREAT | O_LARGEFILE, 0600);
if ( fd > 0 )
{
off_t l = 2047LL * 1024 * 1024 * 1024;
off_t l_new = lseek(fd, l, SEEK_SET);
write(fd, &fd, sizeof(fd));
close(fd);
}
}
$ gcc a.c -o a -std=c99
$ ./a
sizeof(off_t) = 8
$ ls -l test
-rw------- 1 root root 2197949513732 Jan 17 14:26 test