Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. char* permissions(char *file){
  2. struct stat st;
  3. char *modeval = malloc(sizeof(char) * 9 + 1);
  4. if(stat(file, &st) == 0){
  5. mode_t perm = st.st_mode;
  6. modeval[0] = (perm & S_IRUSR) ? 'r' : '-';
  7. modeval[1] = (perm & S_IWUSR) ? 'w' : '-';
  8. modeval[2] = (perm & S_IXUSR) ? 'x' : '-';
  9. modeval[3] = (perm & S_IRGRP) ? 'r' : '-';
  10. modeval[4] = (perm & S_IWGRP) ? 'w' : '-';
  11. modeval[5] = (perm & S_IXGRP) ? 'x' : '-';
  12. modeval[6] = (perm & S_IROTH) ? 'r' : '-';
  13. modeval[7] = (perm & S_IWOTH) ? 'w' : '-';
  14. modeval[8] = (perm & S_IXOTH) ? 'x' : '-';
  15. modeval[9] = '\0';
  16. return modeval;
  17. }
  18. else{
  19. return strerror(errno);
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement