The stat()
and fstat()
functions retrieve a struct stat
, which includes a member st_mode
indicating the file mode, where the permissions are stored.
You can pass this value to chmod()
or fchmod()
after masking out the non-file-permission bits:
struct stat st;
if (stat(file1, &st))
{
perror("stat");
}
else
{
if (chmod(file2, st.st_mode & 07777))
{
perror("chmod");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…