1
0

mode_to_letters.c 798 B

1234567891011121314151617181920212223
  1. #include <sys/stat.h>
  2. #include <string.h>
  3. void mode_to_letters( int mode, char str[] )
  4. {
  5. strcpy( str, "----------" ); /* default=no perms */
  6. if ( S_ISDIR(mode) ) str[0] = 'd'; /* directory? */
  7. if ( S_ISCHR(mode) ) str[0] = 'c'; /* char devices */
  8. if ( S_ISBLK(mode) ) str[0] = 'b'; /* block device */
  9. if ( mode & S_IRUSR ) str[1] = 'r'; /* 3 bits for user */
  10. if ( mode & S_IWUSR ) str[2] = 'w';
  11. if ( mode & S_IXUSR ) str[3] = 'x';
  12. if ( mode & S_IRGRP ) str[4] = 'r'; /* 3 bits for group */
  13. if ( mode & S_IWGRP ) str[5] = 'w';
  14. if ( mode & S_IXGRP ) str[6] = 'x';
  15. if ( mode & S_IROTH ) str[7] = 'r'; /* 3 bits for other */
  16. if ( mode & S_IWOTH ) str[8] = 'w';
  17. if ( mode & S_IXOTH ) str[9] = 'x';
  18. }