|
oflag参数主要有:
O_RDONLY 只读
O_WRONLY 只写
O_RDWR 读写
这些参数都定义在<fcntl.h> 中。
open返回的文件描述符一定是最小的未用描述符数字。
if
(
(
fd =
open(
"file.hole"
,O_RDWR | O_CREAT,
FILE_MODE)
)
<
0)
//别忘创建文件的""
err_sys(
"creat error"
)
;
其中FILE_MODE是作者自己定义的
FILE_MODE在apue.h中定义:
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
S_IRUSR
Permits the file's owner to read it.
S_IWUSR
Permits the file's owner to write to it.
S_IRGRP
Permits the file's group to read it.
S_IWGRP
Permits the file's group to write to it.