博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UNIX 学习笔记-文件I/O(open)
阅读量:4068 次
发布时间:2019-05-25

本文共 974 字,大约阅读时间需要 3 分钟。

open函数:

        函数原型:int  open(const char *pathname,int oflag,.../*,mode_t      mode */);

        其中,pathname为要打开的文件路径及文件名,oflag为文件的打开方式,

       O_RDONLY(只读),

       O_WRONLY( 只写),

       O_RDWR(读写)***这三种类型必须指定其中一种。

      可选参数:

      O_APPEND .         每次写时都从文件末尾开始

      O_CREAT              若文件不存在,则新建,使用该参数时,需要第三个参数mode来说明文件的权限。

      O_EXCL                 测试文件是否存在

      O_TRUNC              若文件存在,且只读只写模式下成功打开,则将文件长度截为0

      O_NOCTTY            如果pathname指的是终端设备,则不将此设备分配作为此进程的控制终端               

      O_SYNC                 使每次w r i t e都等到物理I / O操作完成

        O_NONBLOCK      若pathname指定的是FIFO、块特殊文件或字符特殊文件,则指定本次的打开及后续的I/O

                                       操作为非阻塞模式 

        对于mode,指定的是文件的访问权限,其定义在/usr/include/sys/stat.h中,有以下9种:

       #define S_IRUSR __S_IREAD /* Read by owner.  */

       #define S_IWUSR __S_IWRITE /* Write by owner.  */
       #define S_IXUSR __S_IEXEC /* Execute by owner.  */

       #define S_IRGRP (S_IRUSR >> 3) /* Read by group.  */

       #define S_IWGRP (S_IWUSR >> 3) /* Write by group.  */
       #define S_IXGRP (S_IXUSR >> 3) /* Execute by group.  */

       #define S_IROTH (S_IRGRP >> 3) /* Read by others.  */

       #define S_IWOTH (S_IWGRP >> 3) /* Write by others.  */
       #define S_IXOTH (S_IXGRP >> 3) /* Execdute by others.  */

 

 

转载地址:http://eumji.baihongyu.com/

你可能感兴趣的文章
ceph osd 更换硬盘记录
查看>>
logstash 常见解决方法
查看>>
ceph 故障分析(backfill_toofull)
查看>>
ceph 故障解决备忘
查看>>
更改 ceph journal 位置
查看>>
docker private registry using rados beckend
查看>>
使用 docker 后出现的网络异常现象
查看>>
ceph ( requests are blocked ) 异常解决方法
查看>>
ceph 报警 [ low disk space] 解决
查看>>
python 调用 lvs 脚本 [备忘]
查看>>
openstack 命令行管理二十一 - 云盘管理 (备忘)
查看>>
docker 文件位置[备忘]
查看>>
rhel7 kickstart 参考[备忘]
查看>>
DNS请求分析
查看>>
docker - 资源限制
查看>>
puppet 配置 1. 服务器, 客户端配置说明
查看>>
puppet 配置 2 模块
查看>>
puppet 配置 3. 资源
查看>>
打造自己的 DockerImage
查看>>
rhel7.2 优化技巧
查看>>