#ifndef _SYS_STAT_H_
#define _SYS_STAT_H_
/*
 * The <sys/stat.h> header defines a struct that is used in the stat() and
 * fstat functions on Unix.  The information in this struct comes from the 
 * i-node of some file.  These calls are the only approved way to inspect 
 * i-nodes.
 *
 * N.B.  This interface is mimiced on the QDOS implementation of C68 to
 *      aid in porting programs from Unix to QDOS
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  20 Aug 94   DJW   - Corrected the parameter type for umask() to conform to
 *                      the POSIX/SVR$ standard.
 *                    - Added prototype for mknod() function.
 */

#ifndef _TYPES_H
#include <sys/types.h>
#endif

struct stat 
    {
    dev_t     st_dev;       /* major/minor device number */
    ino_t     st_ino;       /* i-node number */
    mode_t    st_mode;      /* file mode, protection bits, etc. */
    short int st_nlink;     /* # links; TEMPORARY HACK: should be nlink_t*/
    uid_t     st_uid;       /* uid of the file's owner */
    short int st_gid;       /* gid; TEMPORARY HACK: should be gid_t */
    dev_t     st_rdev;
    off_t     st_size;      /* file size */
    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 */
    time_t    st_rtime;
    time_t    st_btime;
    size_t    st_datas;
    size_t    st_blocks;
    size_t    st_blksize;
    };

/* Traditional mask definitions for st_mode. */
#define S_IFMT  0170000     /* type of file */
#define S_IFREG 0100000     /* regular */
#define S_IFBLK 0060000     /* block special */
#define S_IFDIR 0040000     /* directory */
#define S_IFCHR 0020000     /* character special */
#define S_IFIFO 0010000     /* this is a FIFO */
#define S_ISUID 0004000     /* set user id on execution */
#define S_ISGID 0002000     /* set group id on execution */
                /* next is reserved for future use */
#define S_ISVTX   01000	    /* save swapped text even after use */

/* POSIX masks for st_mode. */
#define S_IRWXU   00700     /* owner:  rwx------ */
#define S_IRUSR   00400     /* owner:  r-------- */
#define S_IWUSR   00200     /* owner:  -w------- */
#define S_IXUSR   00100     /* owner:  --x------ */

#define S_IRWXG   00070     /* group:  ---rwx--- */
#define S_IRGRP   00040     /* group:  ---r----- */
#define S_IWGRP   00020     /* group:  ----w---- */
#define S_IXGRP   00010     /* group:  -----x--- */

#define S_IRWXO   00007     /* others: ------rwx */
#define S_IROTH   00004     /* others: ------r-- */ 
#define S_IWOTH   00002     /* others: -------w- */
#define S_IXOTH   00001     /* others: --------x */

/* The following macros test st_mode (from POSIX Sec. 5.6.1.1. */
#define S_ISREG(m)  ((m & S_IFMT) == S_IFREG)   /* is a reg file */
#define S_ISDIR(m)  ((m & S_IFMT) == S_IFDIR)   /* is a directory */
#define S_ISCHR(m)  ((m & S_IFMT) == S_IFCHR)   /* is a char spec */
#define S_ISBLK(m)  ((m & S_IFMT) == S_IFBLK)   /* is a block spec */
#define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)   /* is a pipe/FIFO */


/*
 * Function Prototypes.
 */
#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params)
#endif

/*  Name hiding definitions */

/*  Prototypes */
int chmod    _P_((const char *, int));
int fstat    _P_((int, struct stat *));
int lstat    _P_((const char *, struct stat *));
int mkdir    _P_((const char *, ...)); /* only first parameter relevant on QDOS/SMS */
int mkfifo   _P_((const char *, int));
int mknod    _P_((const char * path, mode_t mode, dev_t dev));
int stat     _P_((const char *, struct stat *));
mode_t umask _P_((mode_t));

#ifdef __LIBRARY__
/*************************************************************************
 *
 *                          C A U T I O N
 *                          ~~~~~~~~~~~~~
 *
 *  The remainder of this header contains definitions that are internal
 *  to the way that the C68 libraries have been implemented on QDOS/SMS.
 *  These definitions should not be used by any user program as they are
 *  subject to change without notice.
 *
 *************************************************************************/

int     _Fstat      _P_((chanid_t, struct stat *));
ino_t   _fake_inode _P_((chanid_t));
int     _Stat       _P_((const char *, struct stat *));

#endif /* __LIBRARY__ */

#undef _P_

#endif  /* _SYS_STAT_H */

