View Full Version : readable filemode from st_mode
using the int generted by st_mode from stat i need to generate the readable file mode
eg drwx-rx etc
im guessing there is a function to do this but cant find it, ive checked the man pages but cannot finda function to do it.
Hammer
12-04-2002, 06:30 PM
After a quick bit of searching, I found this page:
http://www.cs.washington.edu/research/projects/se/www/kde/reuse_patterns/source_code/klyx.src/classes/klyx'FileInfo.html
Look at the function modeString() and follow what it does. Here's a shortened version:
void GetRWX(mode_t i, char *buf)
{
*buf++ = (i & S_IRUSR) ? 'r' : '-';
*buf++ = (i & S_IWUSR) ? 'w' : '-';
*buf++ = (i & S_IXUSR) ? 'x' : '-';
*buf++ = (i & S_IRGRP) ? 'r' : '-';
*buf++ = (i & S_IWGRP) ? 'w' : '-';
*buf++ = (i & S_IXGRP) ? 'x' : '-';
*buf++ = (i & S_IROTH) ? 'r' : '-';
*buf++ = (i & S_IWOTH) ? 'w' : '-';
*buf++ = (i & S_IXOTH) ? 'x' : '-';
*buf = '\0';
}
/* Somewhere esle ... */
char buf[BUFSIZ];
GetRWX(buf.st_mode, buf);
puts(buf);
I don't know if this is the most efficient method or not, I have toyed in the area for sometime :eek:
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.