home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!mudos!mju
- From: mju@mudos.ann-arbor.mi.us (Marc Unangst)
- Subject: Re: Octal chmod status
- Message-ID: <Bt0EEL.H1q@mudos.ann-arbor.mi.us>
- Date: Sat, 15 Aug 1992 05:11:08 GMT
- References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu> <22411@sybase.sybase.com>
- Organization: The Programmer's Pit Stop, Ann Arbor MI
- Lines: 41
-
- In article <17205.2219215579@kcbbs.gen.nz> Rowan_Smith@kcbbs.gen.nz (Rowan Smith) writes:
- > Can somebody please give me a command/method by which I can get the
- > octal equivilant of rwxrwxr-x etc so that I can do the following.
- >
- > set perm = 'octalconv <filename>'
- >
- > is ($perm != 0511) then
- > etc....
-
- Boy, all the solutions that have been offered so far have been pretty
- gross. Might I suggest this one?
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <errno.h>
-
- int
- main(int argc, char **argv)
- {
- struct stat statbuf;
-
- if(argc != 2) {
- fprintf(stderr, "%s: usage: %s file\n", argv[0], argv[0]);
- exit(1);
- }
-
- if(stat(argv[1], &statbuf) != 0) {
- fprintf(stderr, "%s: can't stat file %s: %s\n", argv[0], argv[1],
- strerror(errno));
- exit(1);
- }
-
- printf("%o\n", statbuf.st_mode & 07777);
- exit(0);
- }
-
- --
- Marc Unangst | Real men don't make backups. Real men never
- mju@mudos.ann-arbor.mi.us | accidentally delete files that they're going
- | to need later.
-