home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OS9000
/
APPS
/
rcs.lzh
/
rcs1
/
stat.c
< prev
next >
Wrap
Text File
|
1996-04-22
|
5KB
|
206 lines
static char RCSid[]="$Id: stat.c_v 1.3 96/04/23 02:08:22 hiro Exp $";
/************************************************************
* (C) Copyright 1995
* ARK Systems USA
* All rights reserved.
*
* stat() and fstat() standard libraries
*
* $Date: 96/04/23 02:08:22 $
* $Revision: 1.3 $
*
* $Log: stat.c_v $
* Revision 1.3 96/04/23 02:08:22 hiro
* Ported back to OS-9.
*
* Revision 1.2 96/04/07 00:06:12 hiro
* Ported to OS-9000.
*
************************************************************/
#include <modes.h>
#include <rbf.h>
#ifdef _OS9000
#include <sys/common.h>
#include <sys/unix.h>
#define fildes fd_stats
#define fd_att fd_flag
#define fd_link fd_links
#else
#include <direct.h>
#define bzero(b, s) memset((b),0,(s))
#endif
#include <stdio.h>
#include <errno.h>
#include <sgstat.h>
#include <sg_codes.h>
#include "stat.h"
#ifndef DT_SCF
#include <io.h>
#endif
#ifndef S_IFREG
#define S_IFREG 0
#define S_IFCHR 0
#define S_IFIFO 0
#endif
/*
* Unix stat()
*/
int stat( pathname, sbuf)
char *pathname;
struct stat *sbuf;
{
int path, err;
if ((path = open(pathname,S_IREAD)) == -1) return -1;
err = fstat(path, sbuf);
close(path);
return err;
}
/*
* Unix fstat()
*/
int fstat( path, sbuf)
int path;
struct stat *sbuf;
{
struct fildes fd;
struct sgbuf opt;
#ifdef _OS9000
int err;
u_int32 in;
process_id pid;
u_int16 priority, age, group, user;
int32 schedule;
owner_id oid;
#endif
bzero(sbuf, sizeof(*sbuf));
if( _gs_opt( path, &opt, sizeof(opt) ) < 0 )
return(-1);
#ifdef _OS9000
if ((errno = _os_gs_fd(path, sizeof(fd), &fd)) != 0)
return -1;
sbuf->st_gid = fd.fd_group;
sbuf->st_uid = fd.fd_owner;
sbuf->st_ctime = fd.fd_ctime;
sbuf->st_atime = fd.fd_atime;
sbuf->st_mtime = fd.fd_mtime;
/* Word around OS-90000's stupid protection against _os_gs_fdaddr */
_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 = fd.fd_size;
sbuf->st_ino = in;
sbuf->st_dev = opt.sg_drive;
sbuf->st_rdev = 0;
if (fd.fd_att & S_IREAD) sbuf->st_mode |= S_IRUSR;
if (fd.fd_att & S_IWRITE) sbuf->st_mode |= S_IWUSR;
if (fd.fd_att & S_IEXEC) sbuf->st_mode |= S_IXUSR;
if (fd.fd_att & S_IGREAD) sbuf->st_mode |= S_IRGRP;
if (fd.fd_att & S_IGWRITE) sbuf->st_mode |= S_IWGRP;
if (fd.fd_att & S_IGEXEC) sbuf->st_mode |= S_IXGRP;
#else
if (_gs_gfd(path, &fd, sizeof(fd)) < 0)
return -1;
sbuf->st_gid = (u_char) fd.fd_own[0];
sbuf->st_uid = (u_char) fd.fd_own[1];
{
struct tm tbuf;
tbuf.tm_sec = 0;
tbuf.tm_min = fd.fd_date[4];
tbuf.tm_hour = fd.fd_date[3];
tbuf.tm_mday = fd.fd_date[2];
tbuf.tm_mon = fd.fd_date[1]-1;
tbuf.tm_year = fd.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)fd.fd_dcr[2];
tbuf.tm_mon = (int)fd.fd_dcr[1]-1;
tbuf.tm_year = (int)fd.fd_dcr[0];
sbuf->st_ctime = mktime(&tbuf);
}
memcpy( &sbuf->st_size, fd.fd_fsize, sizeof(time_t));
sbuf->st_dev = opt.sg_dvt - _getsys(D_DevTbl, sizeof(void*))
+ opt.sg_drive;
sbuf->st_ino = opt.sg_fdpsn;
sbuf->st_rdev = 0;
if (fd.fd_att & S_IREAD) sbuf->st_mode |= S_IRUSR;
if (fd.fd_att & S_IWRITE) sbuf->st_mode |= S_IWUSR;
if (fd.fd_att & S_IEXEC) sbuf->st_mode |= S_IXUSR;
#endif
if (fd.fd_att & S_IOREAD) sbuf->st_mode |= S_IROTH;
if (fd.fd_att & S_IOWRITE) sbuf->st_mode |= S_IWOTH;
if (fd.fd_att & S_IOEXEC) sbuf->st_mode |= S_IXOTH;
sbuf->st_mode |= filetype(path, &fd);
sbuf->st_nlink = (short)fd.fd_link;
return(0);
}
static filetype(path, fd)
int path;
struct fildes *fd;
{
struct sgbuf s;
if (fd == NULL )
{
_gs_opt(path, &s);
switch(s.sg_class)
{
case DT_SCF:
return(S_IFCHR);
case DT_PIPE:
return(S_IFIFO);
}
}
return (fd->fd_att & S_IFDIR) ? S_IFDIR : S_IFREG;
}
#define TRUE 1
#define FALSE 0
/*
* _cmpfile() compares 2 files and returns 1 if they are considered
* identical or 0 otherwise
*/
int _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)
{
close(path0);
return(-1);
}
_gs_opt(path0, &iopt, sizeof(iopt));
_gs_opt(path1, &oopt, sizeof(oopt));
close(path0); close(path1);
if (iopt.sg_class == DT_RBF &&
oopt.sg_class == DT_RBF &&
iopt.sg_drive == oopt.sg_drive
#ifndef _OS9000
&& iopt.sg_dvt == oopt.sg_dvt &&
iopt.sg_fdpsn == oopt.sg_fdpsn
#endif
)
return TRUE;
else
return FALSE;
}