代码;
#include
#include
#include
#include
#include
#include
int main()
{
int f;
const char *f_path="test";
mode_t f_attrib;
struct stat *buf=malloc(sizeof(stat));
f_attrib=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH;
f=creat(f_path,f_attrib);
if(f==-1)
{
puts("file create failed!");
}
else
puts("file create success!");
fstat(f,buf);
if(buf->st_mode & S_IRUSR)
puts("all have read authority ");
if(buf->st_mode & S_IRGRP)
puts("group have read authority ");
close(f);
chmod(f_path,0771);
stat(f_path,buf);
if(buf->st_mode & S_IWUSR)
puts("all have write authority ");
if(buf->st_mode & S_IWGRP)
puts("group have write authority ");
free(buf);
return 0;
}
y运行:
文章评论(0条评论)
登录后参与讨论