Код: Выделить всё
[root@cgmachine test]# gcc size.c
size.c: В функции ‘test’:
size.c:31: предупреждение: при инициализации целое преобразуется в указатель без приведения типа
[root@cgmachine test]# ./a.out /dev/sda
off_t size is 8
file_size = -1.
[root@cgmachine test]# g++ size.c
[root@cgmachine test]# ./a.out /dev/sda
off_t size is 8
file_size = 120060444672.
[root@cgmachine test]#Сам исходник
Код: Выделить всё
#define _FILE_OFFSET_BITS 64
#define FOPEN64 1
#define __USE_LARGEFILE64 1
#define _LARGEFILE_SOURCE
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
off_t getfilesize(FILE *f)
{
off_t result = -1;
off_t p=ftello64(f);
if(fseeko64(f, 0, SEEK_END)==0)
{
result=ftello64(f);
fseeko64(f, p, SEEK_SET);
}
return result;
}
void test(char *fname)
{
FILE *f = fopen64(fname, "r");
off_t file_size = getfilesize(f);
fclose(f);
printf("off_t size is %d\n",sizeof(off_t));
printf("file_size = %lld.\n", file_size);
}