- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- int main(int argc, char **argv)
- {
- struct stat stat;
- int fd, zero = 0;
- fd = open("haha.c", O_CREAT, S_IRUSR);
- if(fd < 0){
- printf("open error!\n");
- exit(1);
- }
- fstat(fd, &stat);
- printf("haha.c size = %ld\n", stat.st_size);
- write(fd, &zero, sizeof(zero));
- fstat(fd, &stat);
- printf("haha.c size = %ld\n", stat.st_size);
- exit(0);
- }
复制代码
新建立一个普通文件,大小是0字节,
往里写如数据后,大小应该不为0字节,但是结果:
[xxxx@localhost chap12]$ ./a.out
haha.c size = 0
haha.c size = 0
为什么?
还有,关于文件信息属性的struct stat结构里的st_size,st_blksize,st_blocks有什么区别和联系?
谢谢! |
|