chmod fchmod 系统调用

来源:互联网 发布:ubuntu开机启动服务 编辑:程序博客网 时间:2024/06/06 02:16
#include <stdio.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <stdlib.h>#define RWXRWXRWX (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH |S_IXUSR | S_IXGRP |S_IXOTH )int main(){struct statstatbuf;umask(0);if(creat("foo", RWXRWXRWX) <  0)printf( "creat error for foo!\n" );umask( S_IWGRP |S_IWOTH | S_IROTH );printf("befor creat bar!\n");if(creat("bar", RWXRWXRWX) < 0 )printf("creat error for bar!\n");if( stat( "foo", &statbuf ) <  0 )printf( "stat foo error !\n" );      if( chmod( "foo", ( statbuf.st_mode & ~S_IRUSR & ~S_IWUSR & ~S_IXUSR) | S_ISUID ) < 0 )printf( "chmod foo error!\n" );exit(0);}


运行结果如下:

原创粉丝点击