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.
This is a discussion on readable filemode from st_mode within the Linux Programming forums, part of the Platform Specific Boards category; using the int generted by st_mode from stat i need to generate the readable file mode eg drwx-rx etc im ...
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.
Monday - what a way to spend a seventh of your life
After a quick bit of searching, I found this page:
http://www.cs.washington.edu/researc...;FileInfo.html
Look at the function modeString() and follow what it does. Here's a shortened version:
I don't know if this is the most efficient method or not, I have toyed in the area for sometimeCode: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);![]()
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]