This wiki is built in Notion. Here are all the tips you need to contribute.
也称之为 unbuffered I/O
,与之后的Standard I/O
对照,unbuffered
指的是每个read和write都调用系统内核的系统调用。
stderr
关联起来STDIN_FILENO
STDOUT_FILENO
STDERR_FILENO
以提高可读性open()
& openat()
include <fcntl.h>
int open(const char *path, int oflag, .../* mode_t mode */);
int openat(int fd, const char *path, int oflag, .. /* mode_t mode*/);
// Return: 成功 fd ;失败 -1
path
要打开或创建文件的名字oflag
说明函数的多个选项,选项之间使用|
来连接
O_RDONLY
只读打开,多数被定义为 0O_WRONLY
只写打开 ,1O_RDWR
读、写打开,2O_EXEC
只执行O_SEARCH
只搜索,应用于目录O_APPEND
每次写都追加到文件的结尾;该情况下,lseek
修改偏移量,只对read
有效,对write
无效O_CREAT
文件不存在则创建它O_DIRECTORY
若path
对应的不是目录,则出错O_SYNC
使每次write
等待物理I/O操作完成O_TRUNC
如果文件存在,且为O_RDONLY
或O_RDWR
打开,将其长度截断为0...
表示参数的数量及其类型是可变的重要的参数值介绍:
整体分为三组: