Funkcja stat - uprawnienia

0

Po wywołaniu funkcji stat struktura stat zawiera informacje związane z plikiem. Składowa st_mode tej struktury zawiera tryb pliku i umożliwia obliczenie uprawnień związanych z plikiem. Ale nie wszystkie bity zwróconej liczby są związane z uprawnieniami.
Jak znaleźć te uprawnienia? Mile widziany fragment kodu :)
Pozdr.

0
#define S_IRWXU 0000700    /* RWX mask for owner */
#define S_IRUSR 0000400    /* R for owner */
#define S_IWUSR 0000200    /* W for owner */
#define S_IXUSR 0000100    /* X for owner */

#define S_IRWXG 0000070    /* RWX mask for group */
#define S_IRGRP 0000040    /* R for group */
#define S_IWGRP 0000020    /* W for group */
#define S_IXGRP 0000010    /* X for group */

#define S_IRWXO 0000007    /* RWX mask for other */
#define S_IROTH 0000004    /* R for other */
#define S_IWOTH 0000002    /* W for other */
#define S_IXOTH 0000001    /* X for other */

#define S_ISUID 0004000    /* set user id on execution */
#define S_ISGID 0002000    /* set group id on execution */
#define S_ISVTX 0001000    /* sticky bit */

żywcem wyjęte z man 2 chmod gdzie odesłało mnie man 2 stat [diabel]

Mam dobry humor więc masz tu przykład:

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

struct stat sb;
main()
{
  stat("/etc/master.passwd", &sb);
  if(sb.st_mode & S_IRUSR)
   printf("Plik moze byc czytany przez wlasciciela");
  else
   printf("Wlasciciel nie moze czytac pliku");

 return 0;
}
0

Dzieki

1 użytkowników online, w tym zalogowanych: 0, gości: 1