home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
LIB
/
stat.lzh
/
STAT
/
teststat.c
< prev
Wrap
C/C++ Source or Header
|
1991-08-21
|
2KB
|
121 lines
/*
OS/9 stat/fstat test program
by Richard W.M. Jones
*/
#include <stdio.h>
#include <modes.h>
#include <time.h>
#include "stat.h"
extern int errno;
main(argc,argv)
int argc;
char *argv[];
{
register int i;
for(i=0;i<3;++i)
do_fstat(i);
for(i=1;i<argc;++i)
do_stat(argv[i]);
}
do_stat(pathname)
register char *pathname;
{
struct stat statbuf;
printf("---------- stat on pathname %s\n",pathname);
if(stat(pathname,&statbuf)<0)
{
printf("stat failed on filename %s\n",pathname);
exit(errno);
}
else
printstat(&statbuf);
}
do_fstat(path)
register int path;
{
struct stat statbuf;
printf("---------- fstat on path %d\n",path);
if(fstat(path,&statbuf)<0)
{
printf("fstat failed on path %d\n",path);
exit(errno);
}
else
printstat(&statbuf);
}
char *caltime(n)
time_t n;
{
char *s;
if(n!=-1)
{
s=ctime(&n);
s[strlen(s)-1]=0;
return(s);
}
else
return("-");
}
printstat(statbuf)
register struct stat *statbuf;
{
register char *timestring;
printf("device no.: %d inode no.: %d\n",statbuf->st_dev,
statbuf->st_ino);
printf("protection bits: %04X ",statbuf->st_mode);
decode_prots(statbuf->st_mode);
printf("gid: %d uid: %d size: %d links: %d\n",statbuf->st_gid,
statbuf->st_uid, statbuf->st_size, statbuf->st_nlink);
timestring=caltime(statbuf->st_atime);
printf("last access: %d (%s)\n",statbuf->st_atime,timestring);
timestring=caltime(statbuf->st_mtime);
printf("last modify: %d (%s)\n",statbuf->st_mtime,timestring);
timestring=caltime(statbuf->st_ctime);
printf("creation : %d (%s)\n",statbuf->st_ctime,timestring);
}
decode_prots(protbits)
register int protbits;
{
printf("(");
if(protbits & S_IFIFO)
printf("pipe ");
if(protbits & S_IFCHR)
printf("chr-special ");
if(protbits & S_IFBLK)
printf("blk-special ");
if(protbits & S_IFREG)
printf("reg-file ");
if(protbits & S_IFSOCK)
printf("socket ");
if(protbits & S_IFDIR)
printf("directory ");
if(protbits & S_IFNOSHAR)
printf("non-shar ");
if(protbits & S_IROTH)
printf("PR ");
if(protbits & S_IWOTH)
printf("PW ");
if(protbits & S_IXOTH)
printf("PX ");
if(protbits & S_IREAD)
printf("R ");
if(protbits & S_IWRITE)
printf("W ");
if(protbits & S_IEXEC)
printf("X ");
printf(")\n");
}