#ifndef __STAT_LOADED
#define __STAT_LOADED 1

/* MODIFIED FOR USE WITH SAMBA. SEE STRUCT STAT!!! E. Meyer, 5-Jun-1996 */


/****************************************************************************
**
**  <stat.h> - stat/fstat UNIX emulation functions
**
*****************************************************************************
**  Header introduced by the ISO POSIX-1 Standard
*****************************************************************************
**
**  Copyright Digital Equipment Corporation 1993, 1995. All rights reserved.
**
**  Restricted Rights: Use, duplication, or disclosure by the U.S.
**  Government is subject to restrictions as set forth in subparagraph
**  (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR
**  52.227-14 Alt. III, as applicable.
**
**  This software is proprietary to and embodies the confidential
**  technology of Digital Equipment Corporation. Possession, use, or
**  copying of this software and media is authorized only pursuant to a
**  valid written license from Digital or an authorized sublicensor.
**
******************************************************************************
*/

#pragma __nostandard

/*
** Set up feature test macros
*/
# if defined _XOPEN_SOURCE_EXTENDED && !defined _XOPEN_SOURCE
#   define _XOPEN_SOURCE
# endif

# if defined _XOPEN_SOURCE && _POSIX_C_SOURCE < 2
#   undef  _POSIX_C_SOURCE
#   define _POSIX_C_SOURCE      2
# endif

# if defined _POSIX_SOURCE && _POSIX_C_SOURCE < 1
#   undef  _POSIX_C_SOURCE	    /* _POSIX_SOURCE obsolete.   */
#   define _POSIX_C_SOURCE	1   /* #define _POSIX_C_SOURCE 1 instead */
# endif

# if defined _POSIX_C_SOURCE && !defined _ANSI_C_SOURCE
#   define _ANSI_C_SOURCE
# endif 

# if defined __HIDE_FORBIDDEN_NAMES && !defined _ANSI_C_SOURCE
#   define _ANSI_C_SOURCE
# endif


#ifdef __cplusplus
    extern "C" {
#endif


/*
**  Ensure that regardless of user /pointer_size usage, we begin processing
**  using a short pointer context.
*/
#if __INITIAL_POINTER_SIZE
#   if (__VMS_VER < 70000000) || !defined __ALPHA
#      error " Pointer size usage not permitted before OpenVMS Alpha V7.0"
#   endif
#   pragma __pointer_size __save
#   pragma __pointer_size 32
#endif


/*
**  The DEC C RTL relies on the use of extern_prefix support in the compilers.
**  The scenario of a customer getting these new headers via DEC C++, while at
**  the same time using a compiler before DEC C V5.2 is still supported.
**
**  Note that not having the ability to use #pragma extern_prefix may lead to
**  certain restrictions in the ability to use new functionality.
*/
#if (__DECC_VER > 50230003) || __DECCXX
#   define __CAN_USE_EXTERN_PREFIX 1
#endif


/*
**  Do not naturally align data structures
*/
#pragma __member_alignment __save
#pragma __nomember_alignment


/*
**  Disable warning messages
*/
#if defined __DECC || __DECCXX_VER >= 50000000
#   pragma __message __save
#   pragma __message disable (__MISALGNDSTRCT)
#   pragma __message disable (__MISALGNDMEM)
#endif


/*	 
**  Private typedefs.
*/
#ifndef ____DEV_T 
#   define ____DEV_T 1
    typedef char *__dev_t;
#endif

#ifndef ____GID_T 
#   define ____GID_T 1
    typedef unsigned short __gid_t;
#endif

#ifndef ____INO_T 
#   define ____INO_T 1
#if 0	/* IfN/Mey */
    typedef unsigned short __ino_t;
#else
    typedef unsigned int __ino_t;
#endif
#endif

#ifndef ____MODE_T 
#   define ____MODE_T 1
    typedef unsigned short __mode_t;
#endif

#ifndef ____NLINK_T 
#   define ____NLINK_T 1
    typedef int __nlink_t;
#endif

#ifndef ____OFF_T 
#   define ____OFF_T 1
    typedef int __off_t;
#endif

#ifndef ____TIME_T
#   define ____TIME_T 1
    typedef unsigned long int __time_t;
#endif

#ifndef ____UID_T 
#   define ____UID_T 1
    typedef unsigned int __uid_t;
#endif


/*
**  Create 'public' typedefs that are either insensitive to pointer or are
**  sensitive to pointer size and must use short pointers.
*/
/*	 
**  X/Open definitions
*/
#if defined _XOPEN_SOURCE || (!defined _POSIX_C_SOURCE && !defined _DECC_V4_SOURCE)
#   ifndef __TIME_T
#	define __TIME_T 1
	typedef __time_t time_t;
#   endif

#   ifndef __DEV_T
#	define __DEV_T 1
	typedef __dev_t dev_t;
#   endif

#   ifndef __INO_T
#	define __INO_T 1
	typedef __ino_t ino_t;
#   endif

#   ifndef __NLINK_T
#	define __NLINK_T 1
	typedef __nlink_t nlink_t;
#   endif

#   ifndef __MODE_T
#	define __MODE_T 1
	typedef __mode_t mode_t;
#   endif

#   ifndef __OFF_T
#	define __OFF_T 1
	typedef __off_t off_t;
#   endif

#   ifndef __UID_T
#	define __UID_T 1
	typedef __uid_t uid_t;
#   endif

#   ifndef __GID_T
#	define __GID_T 1
	typedef __gid_t gid_t;
#   endif

#endif

/*	 
**  ISO POSIX-1 defines off_t to be a signed arithmetic type, and
**  requires the st_size field to be of type off_t.  DEC C V5.0
**  and prior declared the field as unsigned.
**
**  Also note that times are given in units of seconds since the
**  Epoch i.e. times returned are measured in seconds since 
**  00:00:00 GMT, Jan. 1, 1970.
*/	 
struct  stat
{
        __dev_t      st_dev;          /* pointer to physical device name */
#if 0	/* modified to meat UNIX standard - only two words are accessable now */
        __ino_t      st_ino[3];       /* 3 words to receive fid */
#else	/* IfN/Mey */
        __ino_t      st_ino   ;       /* 2 words to receive first 2 words of fid */
	unsigned short _st_ino3;      /* the 3. word */
#endif
        __mode_t     st_mode;         /* file "mode" i.e. prot, dir, reg, etc. */
        __nlink_t    st_nlink;        /* for compatibility - not really used */
        __uid_t      st_uid;          /* from ACP - QIO uic field */
        __gid_t      st_gid;          /* group number extracted from st_uid */
#if defined _XOPEN_SOURCE || !defined _POSIX_C_SOURCE
        __dev_t      st_rdev;         /* for compatibility - always zero */
#else
	__dev_t	     st_fill1;
#endif

#ifdef _DECC_V4_SOURCE
	unsigned int st_size;	      /* file size in bytes, was unsigned */
#else
        __off_t      st_size;         /* file size in bytes */
#endif
        __time_t     st_atime;        /* file access time; always same as st_mtime */
        __time_t     st_mtime;        /* last modification time */
        __time_t     st_ctime;        /* file creation time */
#ifndef _POSIX_C_SOURCE
        char         st_fab_rfm;      /* record format */
        char         st_fab_rat;      /* record attributes */
        char         st_fab_fsz;      /* fixed header size */
        unsigned int st_fab_mrs;      /* record size */
#else
	char	     st_fill2[3];
	unsigned int st_fill3;
#endif
};


/*	 
**  DEC C extensions
*/	 
#ifndef _POSIX_C_SOURCE
    typedef	struct stat stat_t; 
#endif


/*	 
**  Private definitions
*/	 
#define __S_IFMT   0170000    /* type of file */
#define __S_IFIFO  0010000    /* pipe or fifo */
#define __S_IFDIR  0040000    /* directory */
#define __S_IFCHR  0020000    /* character special */
#define __S_IFBLK  0060000    /* block special */
#define __S_IFREG  0100000    /* regular */
#define __S_IFMPC  0030000    /* multiplexed char special */
#define __S_IFMPB  0070000    /* multiplexed block special */
#define __S_IFSOCK 0140000    /* socket */
#define __S_IFLNK  0120000    /* symbolic link */


/*	 
**  ISO POSIX-1 definitions
*/	 
#define S_ISUID  0004000    /* set user id on execution */
#define S_ISGID  0002000    /* set group id on execution */

#define S_IRWXU  0000700    /* read,write,execute perm: owner */
#define S_IRUSR  0000400    /* read permission: owner */
#define S_IWUSR  0000200    /* write permission: owner */
#define S_IXUSR  0000100    /* execute/search permission: owner */
#define S_IRWXG  0000070    /* read,write,execute perm: group */
#define S_IRGRP  0000040    /* read permission: group */
#define S_IWGRP  0000020    /* write permission: group */
#define S_IXGRP  0000010    /* execute/search permission: group */
#define S_IRWXO  0000007    /* read,write,execute perm: other */
#define S_IROTH  0000004    /* read permission: other */
#define S_IWOTH  0000002    /* write permission: other */
#define S_IXOTH  0000001    /* execute/search permission: other */

#define S_ISFIFO(m) (((m)& __S_IFMT) == __S_IFIFO)
#define S_ISDIR(m)  (((m)& __S_IFMT) == __S_IFDIR)
#define S_ISCHR(m)  (((m)& __S_IFMT) == __S_IFCHR)
#define S_ISBLK(m)  (((m)& __S_IFMT) == __S_IFBLK)
#define S_ISREG(m)  (((m)& __S_IFMT) == __S_IFREG)


/*	 
**  X/Open XPG4 definitions
*/	 
#if defined _XOPEN_SOURCE || !defined _POSIX_C_SOURCE
#   define S_IFMT   __S_IFMT   /* type of file */
#   define S_IFIFO  __S_IFIFO  /* pipe or fifo */
#   define S_IFDIR  __S_IFDIR  /* directory */
#   define S_IFCHR  __S_IFCHR  /* character special */
#   define S_IFBLK  __S_IFBLK  /* block special */
#   define S_IFREG  __S_IFREG  /* regular */
#endif     


/*	 
**  X/Open XPG4 V2 definitions
*/	 
#if defined _XOPEN_SOURCE_EXTENDED || !defined _POSIX_C_SOURCE
#   define S_IFSOCK __S_IFSOCK /* socket */
#   define S_IFLNK  __S_IFLNK  /* symbolic link */

#   define S_ISLNK(m)  (((m)& S_IFMT) == S_IFLNK)
#   define S_ISSOCK(m) (((m)& S_IFMT) == S_IFSOCK)

#   define S_ISVTX  0001000    /* save swapped text even after use */
#endif


/*	 
**  DEC C extensions
*/	 
#ifndef _POSIX_C_SOURCE
#   define S_IREAD  0000400    /* read permission, owner */
#   define S_IWRITE 0000200    /* write permission, owner */
#   define S_IEXEC  0000100    /* execute/search permission, owner */

#   define S_IFMPC  __S_IFMPC  /* multiplexed char special */
#   define S_IFMPB  __S_IFMPB  /* multiplexed block special */
#endif


/*
**  We are done defining things which must always be short pointers.  If
**  the user has used /pointer_size=short or /pointer_size=long, we will
**  allow ong pointers to be used in function calls.
*/
#if __INITIAL_POINTER_SIZE
#   pragma __pointer_size 64
#endif


/*
**  Beginning in OpenVMS Version 7.0 stat has two implementations. 
**  One for compatibility stat() which returns time in terms of
**  local time and one __utc_stat() which returns time in terms of UTC.
*/
#if __VMS_VER >= 70000000
#   if !defined _VMS_V6_SOURCE
#      ifdef __CAN_USE_EXTERN_PREFIX
#         pragma __extern_prefix __save
#         pragma __extern_prefix "__utc_"
#      else
#         define stat(__p1,__p2)   __utc_stat(__p1,__p2)
#         define fstat(__p1,__p2)  __utc_fstat(__p1,__p2)
#      endif
#   endif
#endif /* __VMS_VER >= 70000000 */


/*
**  Function prototypes
*/
int fstat (int __file_desc, struct stat *__buffer);


/*
**  If we cannot use extern prefix, then the user cannot get the ellipsis form
**  of the prototype.  Applications which must use the optional arguments may
**  either upgrade the compiler or change the call site to use decc$stat or
**  decc$__utc_stat instead of stat.
*/
#if (defined _POSIX_C_SOURCE) || (!defined __CAN_USE_EXTERN_PREFIX)
    int stat  (const char *__path, struct stat *__buf);
#else
    int stat  (const char *__path, struct stat *__buf, ...);
#endif


/*
**  Disable extern_prefix if we enabled it earlier
*/
#if __VMS_VER >= 70000000
#   if !defined _VMS_V6_SOURCE
#      ifdef __CAN_USE_EXTERN_PREFIX
#          pragma __extern_prefix __restore
#      endif
#   endif
#endif

int 	 chmod  (const char *__file_spec, __mode_t __mode);
__mode_t umask  (__mode_t __old_mask);

#ifdef _POSIX_C_SOURCE 
    int mkdir (const char *__dir_spec, __mode_t __mode);
#else
    int mkdir (const char *__dir_spec, __mode_t __mode, ...);
#endif


/*
**  Restore the users pointer context
*/
#if __INITIAL_POINTER_SIZE
#   pragma __pointer_size __restore
#endif

#ifdef __cplusplus
    }
#endif

#if defined __DECC || __DECCXX_VER >= 50000000
#   pragma __message __restore
#endif
#pragma __member_alignment __restore
#pragma __standard
#endif  /* __STAT_LOADED */
