58 lines
824 B
C
58 lines
824 B
C
#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
|