程序4-4 chmod函数实例

 1 //http://blog.chinaunix.net/uid-24549279-id-71355.html
 2 /*
 3  ============================================================================
 4  Name        : test.c
 5  Author      : blank
 6  Version     :
 7  Copyright   : Your copyright notice
 8  Description : 程序4-4 chmod函数实例
 9  ============================================================================
10 */
11 
12 #include <fcntl.h>
13 #include "ourhdr.h"
14 
15 int main(int argc, char *argv[])
16 {
17     struct stat  buf;
18     if (stat("foo", &buf) < 0){
19         err_sys("stat error for foo");
20     }
21     /*
22      * turn on set-group-ID and turn off group-execute
23      */
24     if (chmod("foo", (buf.st_mode & ~S_IXGRP) | S_ISGID) < 0){
25         err_sys("chmod error for foo");
26     }
27 
28     /*
29      *set absolute mode to rw-r--r--
30      */
31     if (chmod("bar", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0){
32         err_sys("chmod error for bar");
33     }
34     exit(0);
35 }

 

posted @ 2014-04-27 12:14  blankqdb  阅读(297)  评论(0编辑  收藏  举报