- 论坛徽章:
- 1
|
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- int main()
- {
- int fd;
- struct stat st;
- if((fd=open("./t",O_WRONLY|O_CREAT|O_TRUNC,666))==0)
- {
- perror("open");
- return -1;
- }
- if(fstat(fd,&st)<0)
- {
- perror("fstat");
- return -2;
- }
- printf("create :%lun",st.st_size);
- if(write(fd,"123",4)!=4)
- {
- perror("write");
- return -3;
- }
- if(fstat(fd,&st)<0)
- {
- perror("fstat");
- return -4;
- }
- printf("after write :%lun",st.st_size);
- close(fd);
- return 0;
- }
复制代码
这是我刚才在Linux 2.6内核 下做的实验.fstat 肯定可以满足你的要求. |
|