p4-6.c
来自「UNIX程序设计教程」· C语言 代码 · 共 25 行
C
25 行
#include <sys/types.h>#include <stdio.h>#include <sys/stat.h>char *get_perms(struct stat *sbuf, char *perms){ static char *modes[] = { /* 与每一种访问权限许可值对应的字符串 */ "---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx" }; int i,j; *perms = '\0'; /* 分别获得三组访问权限值,用该值作为数组modes的下标,以便获得对应的字符串拼入perms */ for (i=2; i>=0; i--) { j=(sbuf->st_mode>>(i*3)) & 07; strcat( perms,modes[j]); } /* 处理调整ID位和sticky位 */ 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_ISUID) !=0) perms[8] = 't'; return perms;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?