Unix/Linux编程实践教程–cp在OS X的实现
2017-05-30 23:00
316 查看
环境:OS X 10.12.4
书中的代码对于OS X是适用的。值得提一嘴的是,其实OS X的open是可以在文件不存在的时候自动创建的,man 2 open时,就可以看到这个说明。
只要在oflag中带有O_CREAT这个标识,就会自动创建不存在的文件。
比如:
MODE可以像书中所写,直接填0644,或者更优雅
这些常量在man 2 chmod中有说明。
书中的代码对于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中有说明。
相关文章推荐
- Unix/Linux编程实践教程--who在OS X的实现
- Unix/Linux编程实践教程–cat在OS X的实现
- Unix/Linux编程实践教程–tail在OS X的实现
- Unix/Linux编程实践教程–head在OS X的实现
- Unix/Linux编程实践教程–od在OS X的实现
- Unix/Linux编程实践教程–last在Ubuntu 14.04的实现
- Unix/Linux编程实践教程----cp1.c详解
- Unix/Linux编程实践教程–ac在Ubuntu 14.04的实现
- Unix/Linux编程实践教程–chmod在Centos7.3的实现
- 解读unix/linux编程实践教程------cp1.c延伸1
- unix/linux编程实践教程:进程和程序
- unix/linux编程实践教程:学习stty
- unix/linux编程实践教程-Emacs常用命令整理
- unix/linux编程实践教程----I/O重定向和管道
- unix/linux编程实践教程------学习笔记(五)
- unix/linux编程实践教程----fflush函数有什么作用
- unix/linux编程实践教程------学习笔记
- unix/linux编程实践教程------学习笔记(四)
- unix/linux编程实践教程:I/O重定向和管道
- Linq实践教程(1):一行代码实现DataTable全文搜索(Full Text Search)