open函数和close函数

open函数和close函数 ​​​​​​文本输入模式#include stdio.h #include sys/types.h //open函数的3个头文件 #include sys/stat.h #include fcntl.h int main() { int fd; //fold describe fd open(/home/ubuntu/mm,O_RDONLY); if(fd -1) { printf(open failed!\n); return -1; } printf(open succeed!\n); return 0; }int open(const char *pathname, intflags, mode_tmode); 打开或创建的文件路径名; 指定打开文件的方式和行为标志 常用值: O_RDONLY只读 O_WRONLY只写 O_RDWR读写 可与下列标志按位或|组合: O_APPEND 表示追加如果原来文件里面有内容则这次写入会写在文件的最末尾。0x00002000 O_CREAT 表示如果指定文件不存在则创建这个文件 0x0000 0100 O_EXCL 表示如果要创建的文件已存在则出错同时返回-1并且修改errno 的值。 O_TRUNC 表示截断如果文件存在并且以只写、读写方式打开则将其长度截断为0。 O_NOCTTY 如果路径名指向终端设备不要把这个设备用作控制终端; 用于指定新创建文件的权限;命令行模式vi hello.c gcc hello.c -o hello touch mm ./hello