home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OS9000
/
APPS
/
diff.lzh
/
diff
/
stat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-24
|
3KB
|
171 lines
#include <modes.h>
#ifdef _OS9000
#include <rbf.h>
#define fildes fd_stats
#define fd_link fd_links
#define fd_att fd_flag
#else
#include <direct.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <sgstat.h>
#include <sg_codes.h>
#include "stat.h"
#ifndef DT_SCF
#include <io.h>
#endif
int stat( pathname, sbuf)
char *pathname;
struct stat *sbuf;
{
struct fildes dp;
struct tm tbuf;
int path, err;
if( ( path = open(pathname,S_IREAD) ) == -1 ) return(-1);
err = fstat(path, sbuf);
close(path);
return(err);
}
int fstat( path, sbuf)
int path;
struct stat *sbuf;
{
#ifdef _OS9000
fd_stats dp;
int err;
u_int32 in;
process_id pid;
u_int16 priority, age, group, user;
int32 schedule;
owner_id oid;
if (err = _os_gs_fd(path, sizeof(dp), &dp))
{
errno = err;
return -1;
}
sbuf->st_uid = dp.fd_owner;
sbuf->st_ctime = dp.fd_ctime;
sbuf->st_atime = dp.fd_atime;
sbuf->st_mtime = dp.fd_mtime;
_os_id(&pid, &priority, &age, &schedule, &group, &user);
oid.grp_usr.grp = 0;
oid.grp_usr.usr = 0;
_os_setuid(oid);
_os_gs_fdaddr(path, &in);
oid.grp_usr.grp = group;
oid.grp_usr.usr = user;
_os_setuid(oid);
sbuf->st_size = dp.fd_size;
sbuf->st_ino = in;
sbuf->st_dev = sbuf->st_rdev = 0;
#else
struct fildes dp;
struct tm tbuf;
struct sgstat opt;
if( _gs_gfd( path, &dp, sizeof( dp ) ) < 0 )
return(-1);
if( _gs_opt( path, &opt, sizeof( opt ) ) < 0 )
return(-1);
sbuf->st_gid = dp.fd_group;
sbuf->st_gid = (u_char) dp.fd_own[0];
sbuf->st_uid = (u_char) dp.fd_own[1];
tbuf.tm_sec = 0;
tbuf.tm_min = dp.fd_date[4];
tbuf.tm_hour= dp.fd_date[3];
tbuf.tm_mday = dp.fd_date[2];
tbuf.tm_mon = dp.fd_date[1]-1;
tbuf.tm_year= dp.fd_date[0];
sbuf->st_mtime = sbuf->st_atime = mktime(&tbuf);
tbuf.tm_sec = tbuf.tm_min = tbuf.tm_hour= 0;
tbuf.tm_mday = (int)dp.fd_dcr[2];
tbuf.tm_mon = (int)dp.fd_dcr[1]-1;
tbuf.tm_year= (int)dp.fd_dcr[0];
sbuf->st_ctime = mktime(&tbuf);
memcpy( &sbuf->st_size, dp.fd_fsize, sizeof(time_t));
sbuf->st_dev = (opt.pd_dvt - _getsys(D_DevTbl, sizeof(*void))
/sizeof(struct devicetbl);
sbuf->st_ino = opt.pd_fdpsn;
sbuf->st_rdev = 0;
#endif
sbuf->st_nlink = (short)dp.fd_link;
sbuf->st_mode = (u_char)dp.fd_att;
sbuf->st_mode |= filetype( path, &dp );
return(0);
}
static filetype( path, dp )
int path;
struct fildes *dp;
{
struct sgbuf s;
if( dp == NULL )
{
_gs_opt( path, &s);
switch( s.sg_class )
{
case DT_SCF:
return(US_IFCHR);
case DT_PIPE:
return(US_IFIFO);
}
}
if( ( dp->fd_att & S_IFDIR) != 0 ) return(US_IFDIR);
return(US_IFREG);
}
#define TRUE 1
#define FALSE 0
cmpfile(a, b)
char *a, *b;
{
struct fildes dp0, dp1;
struct sgbuf iopt,oopt;
int path0, path1;
if( ( path0 = open(a,S_IREAD) ) == -1 ) return(-1);
if( ( path1 = open(b,S_IREAD) ) == -1 ) return(-1);
_gs_opt(path0,&iopt);
_gs_opt(path1,&oopt);
close(path0); close(path1);
if ( iopt.sg_class == 1 &&
oopt.sg_class == 1 &&
iopt.sg_drive == oopt.sg_drive &&
iopt.sg_dvt == oopt.sg_dvt &&
iopt.sg_fdpsn == oopt.sg_fdpsn )
return TRUE;
else
return FALSE;
}
#ifndef __STDC__
void abort()
{
exit(_errmsg(1, "fatal error.\n"));
}
void perror(s)
char *s;
{
static int pn = 0;
int err = errno;
if (!pn && (pn = open("/dd/SYS/errmsg", O_RDONLY)) == -1)
pn = 0;
if (s && *s)
fprintf(stderr, "%s: ", s);
prerr(pn, err);
}
#endif