first commit
This commit is contained in:
commit
21be7fd279
156 changed files with 6939 additions and 0 deletions
57
include/libmu/mode_to_str.h
Normal file
57
include/libmu/mode_to_str.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef _MODE_TO_STR_H
|
||||
#define _MODE_TO_STR_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
char *mu_mode_2_str(mode_t file_mode) {
|
||||
static char mode[11];
|
||||
snprintf(mode, sizeof(mode), "----------");
|
||||
|
||||
if (file_mode & S_IRUSR)
|
||||
mode[1] = 'r';
|
||||
|
||||
if (file_mode & S_IRGRP)
|
||||
mode[4] = 'r';
|
||||
|
||||
if (file_mode & S_IROTH)
|
||||
mode[7] = 'r';
|
||||
|
||||
if (file_mode & S_IWUSR)
|
||||
mode[2] = 'w';
|
||||
|
||||
if (file_mode & S_IWGRP)
|
||||
mode[5] = 'w';
|
||||
|
||||
if (file_mode & S_IWOTH)
|
||||
mode[8] = 'w';
|
||||
|
||||
if (file_mode & S_IXUSR)
|
||||
mode[3] = 'x';
|
||||
|
||||
if (file_mode & S_IXGRP)
|
||||
mode[6] = 'x';
|
||||
|
||||
if (file_mode & S_IXOTH)
|
||||
mode[9] = 'x';
|
||||
|
||||
if (file_mode & S_ISUID) {
|
||||
if (file_mode & S_IXUSR)
|
||||
mode[3] = 's';
|
||||
|
||||
else
|
||||
mode[3] = 'S';
|
||||
}
|
||||
|
||||
if (file_mode & S_ISGID) {
|
||||
if (file_mode & S_IRGRP)
|
||||
mode[6] = 's';
|
||||
|
||||
else
|
||||
mode[6] = 'S';
|
||||
}
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue