From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078712011562.tru64-unix-managers.marc@archive.invalid> From: "Peter Olson, Delphi Information Engineer" Date: Tue, 09 Jun 1998 20:59:23 +0000 To: tru64-unix-managers Subject: SUMMARY: Permissions on a file X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078712011562 I figure I owe the list a contribution in return for all the great stuff I read here, so here is a small C program to solve SSpaldin@mem-ins.com's permissions inquiry. Tested on Digital Unix 3.2c and 4.0 and 4.0B, but it should work on most Unix systems. Peter Olson, Delphi Information Engineer -----------%<---------- /* ** fstatm.c ** ** fstat multiple files. ** ** Public Domain 1998 ** */ #include #include #include int main(int argc, char **argv) { int retcode = 0, showfn = 0; if (argc > 1 && '-' == argv[1][0]) { if ('n' != argv[1][1] || argv[1][2]) { fprintf(stderr, "Usage: fstatm {-n} filenames\n"); fprintf(stderr, " -n causes filenames to be displayed in second column\n"); return 2; } showfn = 1; argv++; argc--; } while (++argv, --argc > 0) /* can run against wildcards */ { struct stat stbuf; if (0 == lstat(argv[0], &stbuf)) /* don't follow symbolic links */ { if (S_ISREG(stbuf.st_mode)) /* is this a regular file? */ stbuf.st_mode &= ~S_IFREG; /* lose the bit that says so */ /* see /usr/include/sys/mode.h for esoteric high order bits */ if (showfn) printf("%3.3lo %s\n", 0x0000FFFFL & (long) stbuf.st_mode, argv[0]); else printf("%3.3lo\n", 0x0000FFFFL & (long) stbuf.st_mode); } else /* placeholder for when we can't get status bits */ { /* real 'no permissions' has 3 digits */ if (showfn) printf("000000 %s\n", argv[0]); else printf("000000\n"); retcode = 1; /* bad path name or other error */ } } return retcode; /* non-zero if one or more fstat errors */ }