get_perms.c 328 B

1234567891011121314151617
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include "access.h"
  4. int get_perms(char *path, int *perms, int *group, int *other)
  5. {
  6. struct stat buf;
  7. if (stat(path, &buf) != 0)
  8. return -1;
  9. *perms = buf.st_mode;
  10. *group = (*perms & GROUP_PERMS) ? 1 : 0;
  11. *other = (*perms & OTHER_PERMS) ? 1 : 0;
  12. return 0;
  13. }