1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Generic substitute for Unix sys/stat.h */
18 
19 #ifndef stat__INCLUDED
20 #  define stat__INCLUDED
21 
22 /* We must include std.h before any file that includes sys/types.h. */
23 #include "std.h"
24 
25 /* Metrowerks Standard Library doesn't use subdirs */
26 #ifdef __MWERKS__
27 #include <stat.h>
28 #else
29 #include <sys/stat.h>
30 #endif
31 
32 /*
33  * Many environments, including the MS-DOS compilers, don't define
34  * the st_blocks member of a stat structure.
35  */
36 #if defined(__SVR3) || defined(__EMX__) || defined(__DVX__) || defined(OSK) || defined(__MSDOS__) || defined(__QNX__) || defined(VMS) || defined(__WIN32__) || defined(__IBMC__) || defined(__BEOS__) || defined(Plan9) || defined(__WATCOMC__)
37 #  define stat_blocks(psbuf) (((psbuf)->st_size + 1023) >> 10)
38 #else
39 #  define stat_blocks(psbuf) ((psbuf)->st_blocks)
40 #endif
41 
42 /*
43  * Microsoft C uses _stat instead of stat,
44  * for both the function name and the structure name.
45  */
46 #ifdef _MSC_VER
47 #  define stat __stat64
48 #  define struct_stat struct __stat64
49 #  define fstat _fstat64
50 #else
51 #define struct_stat struct stat
52 #endif
53 
54 /* Find permissions for file */
55 /* Ideally this would defined in gp.h, but the macroisms mean it has to be
56  * defined here. */
57 extern int gp_stat(const gs_memory_t *mem, const char *path, struct stat *buf);
58 
59 /*
60  * Some (System V?) systems test for directories in a slightly different way.
61  */
62 #if defined(OSK) || !defined(S_ISDIR)
63 #  ifdef S_IFDIR
64 #    define stat_is_dir(stbuf) ((stbuf).st_mode & S_IFDIR)
65 #  else
66 #    ifdef _S_IFDIR
67 #      define stat_is_dir(stbuf) ((stbuf).st_mode & _S_IFDIR)
68 #    endif
69 #  endif
70 #else
71 #  define stat_is_dir(stbuf) S_ISDIR((stbuf).st_mode)
72 #endif
73 
74 /*
75  * Some systems have S_IFMT and S_IFCHR but not S_ISCHR.
76  */
77 #if !defined(S_ISCHR) || !defined(S_ISREG)
78 #  ifndef S_IFMT
79 #    ifdef _S_IFMT
80 #      define S_IFMT _S_IFMT
81 #      define S_IFCHR _S_IFCHR
82 #      define S_IFREG _S_IFREG
83 #    else
84 #    ifdef __S_IFMT
85 #      define S_IFMT __S_IFMT
86 #      define S_IFCHR __S_IFCHR
87 #      define S_IFREG __S_IFREG
88 #    endif
89 #    endif
90 #  endif
91 #  define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
92 #  define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
93 #endif
94 
95 /*
96  * Microsoft C doesn't define S_IRUSR or S_IWUSR.
97  */
98 #ifndef S_IRUSR
99 #  ifndef S_IREAD
100 #    define S_IRUSR _S_IREAD
101 #  else
102 #    define S_IRUSR S_IREAD
103 #  endif
104 #endif
105 #ifndef S_IWUSR
106 #  ifndef S_IWRITE
107 #    define S_IWUSR _S_IWRITE
108 #  else
109 #    define S_IWUSR S_IWRITE
110 #  endif
111 #endif
112 
113 #endif /* stat__INCLUDED */
114