加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Unix/Linux编程实践教程–cp在OS X的实现

发布时间:2020-12-15 16:58:34 所属栏目:安全 来源:网络整理
导读:环境:OS X10.12.4 书中的代码对于OS X是适用的。值得提一嘴的是,其实OS X的open是可以在文件不存在的时候自动创建的,man 2 open时,就可以看到这个说明。 The oflag argument may indicate that the file is to be created if it doesnot exist (by speci

环境:OS X10.12.4

书中的代码对于OS X是适用的。值得提一嘴的是,其实OS X的open是可以在文件不存在的时候自动创建的,man 2 open时,就可以看到这个说明。

The oflag argument may indicate that the file is to be created if it does
not exist (by specifying the O_CREAT flag).  In this case,open() and
openat() require an additional argument mode_t mode; the file is created
with mode mode as described in chmod(2) and modified by the process'
umask value (see umask(2)).

只要在oflag中带有O_CREAT这个标识,就会自动创建不存在的文件。

比如:

open(argv[2],O_WRONLY | O_CREAT,MODE);

MODE可以像书中所写,直接填0644,或者更优雅

#define MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH /* 0644 */

这些常量在man 2 chmod中有说明。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读