FILE *fp;
int fd;
- fp = fopen(“1.c”, “r”);等价于 fd = open(“1.c”,O_RDONLY);
- fp = fopen(“1.c”, “r+“);等价于 fd = open(“1.c”, O_RDWR);
- fp = fopen(“1.c”, “w”); 等价于 fd = open(“1.c”, O_WRONLY | O_CREAT | O_TRUNC, 0666);
- fp = fopen(“1.c”, “w+”); 等价于 fd = open(“1.c”, O_RDWR | O_CREAT | O_TRUNC, 0666);
- fp = fopen(“1.c”, “a”); 等价于 fd = open(“1.c”, O_WRONLY | O_CREAT | O_APPEND, 0666);
- fp = fopen(“1.c”, “a+”); 等价于 fd = open(“1.c”, O_RDWR | O_CREAT | O_APPEND, 0666);
open(“1.c”, O_WRONLY | O_CREAT | O_EXCL, 0666);用于测试文件是否存在,不存在创建,存在报错,返回-1。