/*
 * sys/stat.h for libRILc.

    This file is part of libRILc, a standard C library for GCC on Amiga OS.
    Copyright © 1997, 1998  Rask Ingemann Lambertsen

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    As a special exception, if you link this library with files compiled
    with a GNU compiler to produce an executable, this does not cause the
    resulting executable to be covered by the GNU General Public License.
    This exception does not however invalidate any other reasons why the
    executable file might be covered by the GNU General Public License.
*/

#ifndef _SYS_STAT_H
#define _SYS_STAT_H

#ifdef __cplusplus
extern "C" {
#endif

#include <exec/types.h>
#include <sys/types.h>
#include <time.h>

/* Fix exec/types.h conflict with libg++ */
#undef GLOBAL

struct stat
{
	/* Don't include these fields as long as they are not filled in.
	** Otherwise, applications depending on their values would likely
	** behave in unexpected ways.
	*/
#if 1
	dev_t	st_dev;			/* inode's device */
#endif
	ino_t	st_ino;			/* inode's number */
	mode_t	st_mode;		/* inode protection mode */
#if 0
	nlink_t	st_nlink;		/* number of hard links */
#endif
	uid_t	st_uid;			/* user ID of the file's owner */
	gid_t	st_gid;			/* group ID of the file's group */
	ULONG	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 */
	ULONG	st_blksize;		/* optimal blocksize for I/O */
	ULONG	st_blocks;		/* blocks allocated for file */
	LONGBITS st_flags;		/* user defined flags for file */
};

#define S_IRWXU     (FIBF_DELETE | FIBF_EXECUTE | FIBF_WRITE | FIBF_READ)
#define S_IRUSR     FIBF_READ
#define S_IWUSR     FIBF_WRITE
#define S_IXUSR     FIBF_EXECUTE

#define S_IRWXG     (FIBF_GRP_DELETE | FIBF_GRP_EXECUTE | FIBF_GRP_WRITE | FIBF_GRP_READ)
#define S_IRGRP     FIBF_GRP_READ
#define S_IWGRP     FIBF_GRP_WRITE
#define S_IXGRP     FIBF_GRP_EXECUTE

#define S_IRWXO     (FIBF_OTR_DELETE | FIBF_OTR_EXECUTE | FIBF_OTR_WRITE | FIBF_OTR_READ)
#define S_IROTH     FIBF_OTR_READ
#define S_IWOTH     FIBF_OTR_WRITE
#define S_IXOTH     FIBF_OTR_EXECUTE

#define S_ISTXT     (1 << 7)    /* OS 2.x "hold" bit -> sticky bit. */
#define S_ISVTX     S_ISTXT     /* POSIX version. */

/* MuFS */
#define S_ISUID     (1UL << 31) /* Change UID on execution. */
#define S_ISGID     (1UL << 30) /* Change GID on execution. */

/* File types. */
#define S_IFIFO     0               /* Named pipe (FIFO). */
#define S_IFCHR     (1ULL << 32)    /* Character special. */
#define S_IFDIR     (1ULL << 33)    /* Drawer. */
#define S_IFBLK     0               /* Block special. */
#define S_IFREG     (1ULL << 34)    /* Regular file. */
#define S_IFLNK     (1ULL << 35)    /* Symbolic link. */
#define S_IFSOCK    (1ULL << 36)    /* Socket. */
#define S_IFMT (S_IFIFO | S_IFCHR | S_IFDIR | S_IFBLK | S_IFREG | S_IFLNK | S_IFSOCK)

#define S_ISFIFO(m)     ((m) & S_IFIFO)
#define S_ISCHR(m)      ((m) & S_IFCHR)
#define S_ISDIR(m)      ((m) & S_IFDIR)
#define S_ISBLK(m)      ((m) & S_IFBLK)
#define S_ISREG(m)      ((m) & S_IFREG)
#define S_ISLNK(m)      ((m) & S_IFLNK)
#define S_ISSOCK(m)     ((m) & S_IFSOCK)

int mkdir (const char *drawer, mode_t mode);
int chmod (const char *file, mode_t mode);
int fstat (int fd, struct stat *buf);
int stat (const char *file, struct stat *buf);
int fchmod (int fd, mode_t mode);

#ifdef __cplusplus
}
#endif

#endif /* _SYS_STAT_H */
