博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mkdir
阅读量:6640 次
发布时间:2019-06-25

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

1,mkdir 

Problem: You want to use the  function from the  POSIX header, but you don’t know what the mode_t argument should look like.

Solution:

For a detailed reference, see the 

The first argument should be obvious - just enter the path name of the directory you intend to create. If you use a  (in C++); use it’s c_str() member function to get a C string.

The second argument defines the permissions the newly created directory shall have. This How-to assumes you’re already familiar with Unix file permissions. If you are not, please read the .

First, decide which rights the directory shall have. This boils down to these 9 questions:

  • Shall the owner be able to read/write/execute?
  • Shall the group be able to read/write/execute?
  • Shall everyone else (= others) be able to read/write/execute? The second argument has the type mode_t, but this is basically just an alias for any type of integer.

sys/stat.h provides you with several integers you can bytewise-OR (|) together to create your mode_t:

  • User: S_IRUSR (read), S_IWUSR (write), S_IXUSR (execute)
  • Group: S_IRGRP (read), S_IWGRP (write), S_IXGRP (execute)
  • Others: S_IROTH (read), S_IWOTH (write), S_IXOTH (execute)

Additionally, some shortcuts are provided (basically a bitwise-OR combination of the above

  • Read + Write + Execute: S_IRWXU (User), S_IRWXG (Group), S_IRWXO (Others)
  • DEFFILEMODE: Equivalent of 0666 = rw-rw-rw-
  • ACCESSPERMS: Equivalent of 0777 = rwxrwxrwx Therefore, to give only the user rwx (read+write+execute) rights whereas group members and others may not do anything, you can use any of the following mkdir() calls equivalently:
mkdir("mydir", S_IRUSR | S_IWUSR | S_IXUSR); mkdir("mydir", S_IRWXU);

In order to give anyone any rights (mode 0777 = rwxrwxrwx), you can use any of the following calls equivalently:

mkdir("mydir", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH); mkdir("mydir", S_IRWXU | S_IRWXG | S_IRWXO); mkdir("mydir", ACCESSPERMS);

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

你可能感兴趣的文章
Django ---Form的字段、选择下拉框\radio\checkbox
查看>>
MongoDB投影有$slice如何只显示该字段
查看>>
1068. [SCOI2007]压缩【区间DP】
查看>>
XML 的简介与开发
查看>>
拍立得
查看>>
OK335xS 系统启动配置解析
查看>>
linux service等命令不能使用的解决办法
查看>>
命名空间
查看>>
转载----Python的strip()函数
查看>>
下载远程(第三方服务器)文件、图片,保存到本地(服务器)的方法、保存抓取远程文件、图片...
查看>>
Docker四种网络模式
查看>>
c:url标签
查看>>
Silverlight-Validation服务器端异步数据验证
查看>>
最新VIN(车辆识别码)解析
查看>>
merge sort and quick sort 自己去理解吧
查看>>
CodeForces 447C DZY Loves Sequences DP
查看>>
文件打包下载
查看>>
Android 数据库管理— — —升级数据库
查看>>
Linux学习之让进程在后台可靠运行的方法详解
查看>>
ubuntu下出现的问题-控制台更新源失败
查看>>