home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
LIB
/
unix.zoo
/
stat.c
< prev
next >
Wrap
Text File
|
2009-11-06
|
7KB
|
181 lines
/***************************************************************************/
/* */
/* stat() : Unix library (OS9/68000) */
/* ====== */
/* */
/* Author: K. Schmitt */
/* Compiler: Microware C Vers. 3.0 */
/* OS: OS9/68000 Vers. 2.2 */
/* */
/* Edition History */
/* =============== */
/* */
/* Ed. 0.00 Date 11/16/88 */
/* First version */
/* */
/***************************************************************************/
/* */
/* Description */
/* */
/*
NAME
stat, fstat - get file status
SYNOPSIS
#include <UNIX/stat.h>
int stat (path, buf)
char *path;
struct stat *buf;
int fstat (fildes, buf)
int fildes;
struct stat *buf;
DESCRIPTION
Path points to a path name naming a file. Read, write or
execute permission of the named file is not required, but
all directories listed in the path name leading to the file
must be searchable. Stat obtains information about the
named file.
Fstat obtains information about an open file known by the
file descriptor fildes, obtained from a successful open,
creat, dup, fcntl, or pipe system call.
Buf is a pointer to a stat structure into which information
is placed concerning the file.
The contents of the structure pointed to by buf include the
following members:
ushort st_mode; File mode
ino_t st_ino; Inode number
dev_t st_dev; ID of device containing a directory
entry for this file
dev_t st_rdev; ID of device. This entry is defined
only for character special or block
special files
short st_nlink; Number of links
ushort st_uid; User ID of the file's owner
ushort st_gid; Group ID of the file's group
off_t st_size; File size in bytes
time_t st_atime; Time of last access
time_t st_mtime; Time of last data modification
time_t st_ctime; Time of last file status change
Times measured in seconds since
00:00:00 GMT, Jan. 1, 1970
The following parameters are affected by different system
calls:
st_atime Time when file data was last accessed.
Changed by the following system calls: creat,
mknod, pipe, utime, and read.
st_mtime Time when data was last modified.
Changed by the following system calls: creat,
mknod, pipe, utime, and write.
st_ctime Time when file status was last changed.
Changed by the following system calls: chmod,
chown, creat, link, mknod, pipe, unlink, utime,
and write.
Stat will fail if one or more of the following are true:
[ENOTDIR] A component of the path prefix is not a
directory.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied for a component
of the path prefix.
[EFAULT] Buf or path points to an invalid address.
Fstat will fail if one or more of the following are true:
[EBADF] Fildes is not a valid open file descriptor.
[EFAULT] Buf points to an invalid address.
RETURN VALUE
Upon successful completion a value of 0 is returned.
Otherwise, a value of -1 is returned and errno is set to
indicate the error.
*/
#include <UNIX/stat.h>
#include <direct.h>
#include <dir.h>
extern time_t _secsince70 ();
int stat (fname, buf)
char fname [];
struct stat *buf;
{
int fd, ret;
DIR *dirp;
if ((fd = open (fname, S_IREAD)) == -1)
{
if ((dirp = opendir (fname)) == 0)
return (-1);
fd = dirp -> dd_fd;
}
else
{
dirp = 0;
}
ret = fstat (fd, buf);
if (dirp == 0) close (fd);
else closedir (dirp);
return (ret);
} /* end of stat */
int fstat (fd, buf)
int fd;
register struct stat *buf;
{
struct fildes fildes;
register int i;
register char *p;
char *malloc();
if (_gs_gfd (fd, &fildes, sizeof (struct fildes)) == -1)
return (-1);
buf -> st_uid = (unsigned short) (fildes.fd_own [0]);
buf -> st_gid = (unsigned short) (fildes.fd_own [1]);
buf -> st_mode = (unsigned short) (fildes.fd_att) & 0377;
buf -> st_nlink = (unsigned short) (fildes.fd_link);
for (i = 0, p = (char *) (&buf -> st_size); i < 4; i++)
{
*p++ = fildes.fd_fsize [i];
}
buf -> st_atime = buf -> st_mtime = _secsince70 (fildes.fd_date);
fildes.fd_dcr [3] = 0;
fildes.fd_dcr [4] = 0;
buf -> st_ctime = _secsince70 (fildes.fd_dcr);
if ((buf -> st_rdev = buf -> st_dev = malloc(30)) != (char *) 0)
{
_gs_devn (fd, buf -> st_dev);
}
return (0);
} /* end of fstat */