st_mode confusion

Started by
1 comment, last by pdstatha 22 years, 1 month ago
I am trying to figure out stat.h, the part where the mode bits are set for the file access permissions. I have found the following information. http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_278.html#SEC287 Only problem is I can''t make head or tails of it, can someone help me by providing an example or something??
Advertisement
Ok i''ve written my interpretation of the mode bits. Basically what the following code snippet should do is check if the bit representing read permissions for the user is set, then it should print an "r" else it will print "-".

  struct stat sbuf;mode_t mode;if(argv[1] !=''\0''){   if(lstat(argv[1],&sbuf) != -1){      mode = sbuf.st_mode;      if(mode == S_IRUSR)         printf("r");      else         printf("-");   }else      printf("Can''t stat %s\n", argv[1]);}else   printf("Usage:%s file_name\n",argv[0]);  
You really should stop cross posting here and General Programming. Pick a forum and stick with it.

Also, you''ve been asking a lot of basic UNIX architecture/programming questions. I suggest you peruse your local public/university library for several excellent references. It''ll be faster for you, will give you broader information on more topics, and will then allow you use this forum for interesting specific application questions - which means you''ll get better answers.

That''s my recommendation, at least.

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement