_FILE_OFFSET_BITS 64 를 이용해서 stat() 함수 사용하려고 하는

black0328의 이미지

소스 코드

#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int main( char *argc, char **argv )
{
        struct stat statbuf;
        stat( argv[1] , &statbuf );

        printf("sizeof(off_t) = %d\n",sizeof(off_t));
        printf("sizeof(unsigned long) = %d\n",sizeof(unsigned long) );
        printf("sizeof( unsigned long long ) = %d \t size = %11u \n",sizeof (unsigned long long ), (unsigned long long) statbuf.st_size );
        printf("sizeof( unsigned long long int ) = %d\t size = %11u \n", sizeof( unsigned long long int ),(unsigned long long int) statbuf.st_size );
        return 0;
}

실행 결과 값

offistor:/home1/test# ./size test5G
sizeof(off_t) = 8
sizeof(unsigned long) = 4
sizeof( unsigned long long ) = 8         size =   947912704 
sizeof( unsigned long long int ) = 8     size =   947912704 

실질 ls -l 의 결과는

offistor:/home1/test# ls -l
합계 14336012
-rwxr-xr-x    1 root     root         5410  2월 28 16:04 size
-rw-r--r--    1 root     root          604  2월 28 16:04 size.c
-rw-r--r--    1 root     root     2097152000  2월 27 18:08 test2G
-rw-r--r--    1 root     root     3145728000  2월 27 18:10 test3G
-rw-r--r--    1 root     root     4194304000  2월 27 18:15 test4G
-rw-r--r--    1 root     root     5242880000  2월 28 13:38 test5G

입니다..

test4G 파일가지는 ls -l 과 결과 값이 같습니다.
그러나 test5G 파일은 결과 값이 다릅니다.

제 소스에서 잘못된 점이 있어서 sizeof(unsinged long long int ), sizeof(usnigned long long ) 은 8byte 인뎅....결과값이 다르게 나오는지 답변 부탁드립니다.

kslee80의 이미지

%11u 대신에 %lld 를 사용해 보세요.

black0328의 이미지

아.....

말슴대로 %lld , %llu 를 사용하니 됩니다.
전 %11d,%11u 인줄 알았었는데...--;;
감사합니다.