实战chmod函数 fchmod fchmodat

来源:互联网 发布:贪吃飒淘宝小店网址 编辑:程序博客网 时间:2024/05/16 11:34
  1 #include "apue.h"
  2 #include <fcntl.h>
  3
  4 int main()
  5 {
  6         struct stat statbuf;
  7         if( stat("without_umask",&statbuf) < 0)
  8                 err_sys("stat error");
  9
 10         if( chmod("without_umask", (statbuf.st_mode & ~S_IWGRP) | S_ISGID) < 0)
 11                 err_sys("chmod error");
 12
 13         if( chmod("after_umask", S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
 14                 err_sys("chmod2 error");
 15
 16         exit(0);

 17 }


-rw-r-Srw- 1 tingbinz tingbinz       0 Sep 14 02:31 without_umask
-rw-r--r-- 1 tingbinz tingbinz       0 Sep 14 02:31 after_umask

0 0