/*
若没有文件,则创建新文件,若有文件,则APPEND打开
笔记 循环打开同一个文件,每次都是不同的文件描述符,每次都有一个文件表项,指向同一个V节点表项
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char const *argv[])
{
int fd;
int i;
char tmp='a';
for(i=0;i<10;i++)
{
fd=open("test.txt",O_CREAT|O_RDWR|O_APPEND,0777);
printf("%d %d\n",i,fd);
write(fd,&tmp,1);
tmp++;
}
}
/*
./a.out
0 3
1 4
2 5
3 6
4 7
5 8
6 9
7 10
8 11
9 12
od -c test.txt
0000000 a b c d e f g h i j
0000012
*/
文件I/O-006.没有文件时 创建新的,若有则APPEND打开
最新推荐文章于 2022-01-26 11:43:43 发布