现在的位置: 首页 > 综合 > 正文

Linux 下的 mkdir 函数

2013年10月21日 ⁄ 综合 ⁄ 共 2186字 ⁄ 字号 评论关闭
Code:
  1. Linux 下的 mkdir 函数
  2.  
  3.   
  4.   
  5. 原型:int mkdir (const char *filename, mode_t mode)  
  6.   
  7. 返回0表示成功,返回-1表述出错。使用该函数需要包含头文件
  8.    #include<sys/stat.h>
  9.    #include<sys/types.h>
  10.  
  11. mode 表示新目录的权限,可以取以下值:  
  12.   
  13. S_IRUSR  
  14. S_IREAD  
  15. Read permission bit for the owner of the file. On many systems this bit is 0400. S_IREAD is an obsolete synonym provided for BSD compatibility.  
  16.   
  17. S_IWUSR  
  18. S_IWRITE  
  19. Write permission bit for the owner of the file. Usually 0200. S_IWRITE is an obsolete synonym provided for BSD compatibility.  
  20.   
  21. S_IXUSR  
  22. S_IEXEC  
  23. Execute (for ordinary files) or search (for directories) permission bit for the owner of the file. Usually 0100. S_IEXEC is an obsolete synonym provided for BSD compatibility.  
  24.   
  25. S_IRWXU  
  26. This is equivalent to (S_IRUSR | S_IWUSR | S_IXUSR).  
  27.   
  28. S_IRGRP  
  29. Read permission bit for the group owner of the file. Usually 040.  
  30.   
  31. S_IWGRP  
  32. Write permission bit for the group owner of the file. Usually 020.  
  33.   
  34. S_IXGRP  
  35. Execute or search permission bit for the group owner of the file. Usually 010.  
  36.   
  37. S_IRWXG  
  38. This is equivalent to (S_IRGRP | S_IWGRP | S_IXGRP).  
  39.   
  40. S_IROTH  
  41. Read permission bit for other users. Usually 04.  
  42.   
  43. S_IWOTH  
  44. Write permission bit for other users. Usually 02.  
  45.   
  46. S_IXOTH  
  47. Execute or search permission bit for other users. Usually 01.  
  48.   
  49. S_IRWXO  
  50. This is equivalent to (S_IROTH | S_IWOTH | S_IXOTH).  
  51.   
  52. S_ISUID  
  53. This is the set-user-ID on execute bit, usually 04000. See How Change Persona.  
  54.   
  55. S_ISGID  
  56. This is the set-group-ID on execute bit, usually 02000. See How Change Persona.  
  57.   
  58. S_ISVTX  
  59. This is the sticky bit, usually 01000.   

 Linux下mkdir函数
头文件库:

 

#include <sys/stat.h>

 

#include <sys/types.h>

 

  函数原型:

 

int mkdir(const char *pathname, mode_t mode);

 

函数说明:

 

mkdir()函数以mode方式创建一个以参数pathname命名的目录,mode定义新创建目录的权限。

 

返回值:

 

若目录创建成功,则返回0;否则返回-1,并将错误记录到全局变量errno中。

 

mode方式:

 
S_IRWXU 00700权限,代表该文件所有者拥有读,写和执行操作的权限
S_IRUSR(S_IREAD) 00400权限,代表该文件所有者拥有可读的权限
S_IWUSR(S_IWRITE) 00200权限,代表该文件所有者拥有可写的权限
S_IXUSR(S_IEXEC) 00100权限,代表该文件所有者拥有执行的权限
S_IRWXG 00070权限,代表该文件用户组拥有读,写和执行操作的权限
S_IRGRP 00040权限,代表该文件用户组拥有可读的权限
S_IWGRP 00020权限,代表该文件用户组拥有可写的权限
S_IXGRP 00010权限,代表该文件用户组拥有执行的权限
S_IRWXO 00007权限,代表其他用户拥有读,写和执行操作的权限
S_IROTH 00004权限,代表其他用户拥有可读的权限
S_IWOTH 00002权限,代表其他用户拥有可写的权限
S_IXOTH 00001权限,代表其他用户拥有执行的权限
 

抱歉!评论已关闭.