Go to the source code of this file.
Functions | |
void | permstring (char *perms, int mode) |
Produce a string representation of Unix mode bits like that used by ls(1). More... |
|
Produce a string representation of Unix mode bits like that used by ls(1).
Definition at line 29 of file permstring.c. Referenced by list_file(), and list_file_entry().
00031 { 00032 static const char *perm_map = "rwxrwxrwx"; 00033 int i; 00034 00035 strcpy(perms, "----------"); 00036 00037 for (i=0;i<9;i++) { 00038 if (mode & (1<<i)) perms[9-i] = perm_map[8-i]; 00039 } 00040 00041 /* Handle setuid/sticky bits. You might think the indices are 00042 * off by one, but remember there's a type char at the 00043 * start. */ 00044 if (mode & S_ISUID) 00045 perms[3] = (mode & S_IXUSR) ? 's' : 'S'; 00046 00047 if (mode & S_ISGID) 00048 perms[6] = (mode & S_IXGRP) ? 's' : 'S'; 00049 00050 if (mode & S_ISVTX) 00051 perms[9] = (mode & S_IXOTH) ? 't' : 'T'; 00052 00053 if (S_ISLNK(mode)) perms[0] = 'l'; 00054 if (S_ISDIR(mode)) perms[0] = 'd'; 00055 if (S_ISBLK(mode)) perms[0] = 'b'; 00056 if (S_ISCHR(mode)) perms[0] = 'c'; 00057 if (S_ISSOCK(mode)) perms[0] = 's'; 00058 if (S_ISFIFO(mode)) perms[0] = 'p'; 00059 } |