- 论坛徽章:
- 0
|
初学者、刚看UNIX环境高级编程,看不懂这个小程序,
求教!
其中程序中两文件的状态为
bar -rw------
foo -rw-rw-rw
详见 UNIX环境高级编程 程序清单4-4 chmod函数实例
代码如下:
#include "apue.h"
int
main (void)
{
struct stat statbuf;
/* turn on set-group-id and turn off group-execute*/
if(stat("foo", &statbuf) < 0)
err_sys("stat error for foo");
if(chmod ("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0)
err_sys("chmod error for foo");
/*set absolute mode to "rw-r--r--"*/
if(chmod("stat", S_IRUSR | S_IWUSR | S_IRGRP | S_IWOTH) < 0)
err_sys("chmod error for bar");
exit (0);
}
运行程序后两个文件的状态为:
bar -rw-r--r--
foo -rw-rwSrw- |
|