home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3493 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.5 KB  |  52 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!mudos!mju
  3. From: mju@mudos.ann-arbor.mi.us (Marc Unangst)
  4. Subject: Re: Octal chmod status
  5. Message-ID: <Bt0EEL.H1q@mudos.ann-arbor.mi.us>
  6. Date: Sat, 15 Aug 1992 05:11:08 GMT
  7. References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu> <22411@sybase.sybase.com>
  8. Organization: The Programmer's Pit Stop, Ann Arbor MI
  9. Lines: 41
  10.  
  11. In article <17205.2219215579@kcbbs.gen.nz> Rowan_Smith@kcbbs.gen.nz (Rowan Smith) writes:
  12. >   Can somebody please give me a command/method by which I can get the 
  13. >   octal equivilant of rwxrwxr-x etc so that I can do the following.
  14. >
  15. >   set perm = 'octalconv <filename>'
  16. >
  17. >   is ($perm != 0511) then
  18. >      etc....
  19.  
  20. Boy, all the solutions that have been offered so far have been pretty
  21. gross.  Might I suggest this one?
  22.  
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <errno.h>
  27.  
  28. int
  29. main(int argc, char **argv)
  30. {
  31.   struct stat statbuf;
  32.  
  33.   if(argc != 2) {
  34.     fprintf(stderr, "%s: usage: %s file\n", argv[0], argv[0]);
  35.     exit(1);
  36.   }
  37.  
  38.   if(stat(argv[1], &statbuf) != 0) {
  39.     fprintf(stderr, "%s: can't stat file %s: %s\n", argv[0], argv[1],
  40.         strerror(errno));
  41.     exit(1);
  42.   }
  43.  
  44.   printf("%o\n", statbuf.st_mode & 07777);
  45.   exit(0);
  46. }
  47.  
  48. -- 
  49. Marc Unangst                | Real men don't make backups.  Real men never
  50. mju@mudos.ann-arbor.mi.us   | accidentally delete files that they're going
  51.                             | to need later.
  52.