UNIX系统中的文件、目录操作与设备I/O控制
1. 文件权限与属性操作
在UNIX系统中,文件权限和属性的操作是非常基础且重要的部分。以下是一段用于处理文件权限输出的代码:
*perms = NULL;
for (i=2; i >= 0; i--) {
/*
* Since we're subscripting, we don't
* need the constants. Just get a
* value between 0 and 7.
*/
j = (sbuf.st_mode >> (i*3)) & 07;
/*
* Get the perm bits.
*/
strcat(perms, modes[j]);
}
/*
* Handle special bits which replace the 'x'
* in places.
*/
if ((sbuf.st_mode & S_ISUID) != 0)
perms[2] = 's';
if ((sbuf.st_mode & S_ISGID) != 0)
perms[5] = 's';
if ((sbuf.st_mode & S_ISVTX) != 0)
perms[8] = 't';
/*
* Print permissions, number of links,
* user and group ids.
*/
printf("%s%3d %5d
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



