#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
char const * sperm(__mode_t mode) {
static char local_buff[16] = {0};
int i = 0;
// user permissions
if ((mode & S_IRUSR) == S_IRUSR) local_buff[i] = 'r';
else local_buff[i] = '-';
i++;
if ((mode & S_IWUSR) == S_IWUSR) local_buff[i] = 'w';
else local_buff[i] = '-';
i++;
if ((mode & S_IXUSR) == S_IXUSR) local_buff[i] = 'x';
else local_buff[i] = '-';
i++;
// group permissions
if ((mode & S_IRGRP) == S_IRGRP) local_buff[i] = 'r';
else local_buff[i] = '-';
i++;
if ((mode & S_IWGRP) == S_IWGRP) local_buff[i] = 'w';
else local_buff[i] = '-';
i++;
if ((mode & S_IXGRP) == S_IXGRP) local_buff[i] = 'x';
else local_buff[i] = '-';
i++;
// other permissions
if ((mode & S_IROTH) == S_IROTH) local_buff[i] = 'r';
else local_buff[i] = '-';
i++;
if ((mode & S_IWOTH) == S_IWOTH) local_buff[i] = 'w';
else local_buff[i] = '-';
i++;
if ((mode & S_IXOTH) == S_IXOTH) local_buff[i] = 'x';
else local_buff[i] = '-';
i++;
return local_buff;
}
int main(int argc, char ** argv)
{
std::cout<<sperm(S_IRUSR | S_IXUSR | S_IWGRP | S_IROTH)<<std::endl;
std::cout<<sperm(S_IRUSR)<<std::endl;
std::cout<<sperm(S_IRUSR | S_IRGRP | S_IWOTH | S_IROTH)<<std::endl;
return 0;
}