readable filemode from st_mode

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 ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    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.
    Monday - what a way to spend a seventh of your life

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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:
    Code:
    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
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Required!!!!!
    By bobthebullet990 in forum C Programming
    Replies: 14
    Last Post: 11-27-2005, 02:56 PM
  2. displaying file permissions
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 11-26-2005, 06:04 AM
  3. File IO, .ini readable?
    By Zeusbwr in forum C++ Programming
    Replies: 7
    Last Post: 10-13-2004, 12:33 AM
  4. Most readable way to organize variables and files?
    By SourceCode in forum C Programming
    Replies: 4
    Last Post: 04-19-2003, 02:19 AM
  5. How to convert object file back to readable?
    By Yin in forum C++ Programming
    Replies: 5
    Last Post: 03-14-2002, 08:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21