From: "Peter Olson, Delphi Information Engineer" <PETER () delphi ! com>
To: tru64-unix-managers
Subject: SUMMARY: Permissions on a file
Date: Tue, 09 Jun 1998 20:59:23 +0000 [thread overview]
Message-ID: <96078712011562.tru64-unix-managers.marc@archive.invalid> (raw)
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 <stdio.h>
#include <sys/stat.h>
#include <sys/mode.h>
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 */
}
next reply other threads:[~1998-06-09 20:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-06-09 20:59 Peter Olson, Delphi Information Engineer [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-06-09 19:34 SUMMARY: Permissions on a file Spalding, Stephen
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox