1. open函数
-
包含头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> -
函数原型
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode); -
函数功能
打开一个文件,并返回文件描述符。
-
函数参数
- pathname:文件名
- flags:
- 必选参数(下面三个必须要有一个)
- O_RDONLY :只读
- O_WRONLY :只写
- O_RDWR :可读可写
- 可选参数(仅列出常用参数)
- O_APPEND :追加的方式打开,The file is opened in append mode.
- O_CREAT :如果文件不存在则创建,If the file does not exist it will be created.
- O_EXCL :和O_CREAT一块使用,如果文件存在则报错,if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
- O_NONBLOCK :非阻塞的方式打开文件
- 必选参数(下面三个必须要有一个)
Linux系统API:open()与close()函数详解

本文介绍了Linux系统API中的open()和close()函数,详细讲解了它们的功能、参数及使用。open()用于打开文件,根据参数支持只读、只写和读写模式,以及文件创建和追加等选项。close()函数则用于关闭已打开的文件描述符。此外,还展示了如何结合这两个函数实现touch命令。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



