- 论坛徽章:
- 1
|
我知道是怎么回事了。
FreeBSD 上的 statbuf.st_size 是 64 位的,因此得用 %lld 来 printf
- $ cat ttt.c
- # include <sys/stat.h>
- # include <errno.h>
- char *filename = "/etc/passwd";
- int main( void )
- {
- struct stat statbuf;
- if ( stat(filename, &statbuf) == -1 ){
- perror( filename );
- return -1;
- }
- printf( "Size: %ld\n", statbuf.st_size );
- printf( "Last Access Time: %s", ctime( &statbuf.st_atime ) );
- printf( "sizeof st_size: [%d]\n", sizeof(statbuf.st_size) );
- printf( "Size: %lld \t Last Access Time: %s\n", statbuf.st_size,
- ctime( &(statbuf.st_atime) ) );
- printf( "\n------------\n" );
- return 0;
- }
- $ cc -o ttt ttt.c
- $ ./ttt
- Size: 1376
- Last Access Time: Fri Apr 28 15:49:33 2006
- sizeof st_size: [8]
- Size: 1376 Last Access Time: Fri Apr 28 15:49:33 2006
- ------------
复制代码 |
|