1 /*
2 		    Low Level Interface Library
3 
4 	Copyright 1983-2008 Green Hills Software,Inc.
5 
6  *  This program is the property of Green Hills Software, Inc,
7  *  its contents are proprietary information and no part of it
8  *  is to be disclosed to anyone except employees of Green Hills
9  *  Software, Inc., or as agreed in writing signed by the President
10  *  of Green Hills Software, Inc.
11  *
12  *  This header file is #included by all of the files in the Low Level
13  *  Interface Library (libsys.a).
14  *
15  *  The various versions of Unix differ slightly in the content of this file
16  *  but they differ greatly in where the information is kept in the local
17  *  include files.  In addition, this header file must work correctly with
18  *  and without the Green Hills Ansi C header files, which sometimes conflict
19  *  with local include files.  Of course, if this is not native Unix, we may
20  *  not have any local include files.
21  *
22  *  Therefore, we support 3 approaches.  In the first, only native header files
23  *  are used.  The Green Hills Ansi C header files are not used at all.  This
24  *  mode is appropriate for Unix System V.4 and any other Unix like environment
25  *  which has been updated to Ansi C.
26  *
27  *  In the second, no native header files are used.  The Green Hills Ansi C
28  *  header files are used for generic information and system specific
29  *  information is provided directly in this file.
30  *
31  *  In the third, and most difficult situation, both native Unix and Green Hills
32  *  Ansi C header files are used.  This invariably results in conflicts.
33  *
34 */
35 
36 #ifdef __cplusplus		/* If C++ compiler, use C linkage */
37 extern "C" {
38 #endif
39 
40 #include "inddef.h"
41 #include "inderrno.h"
42 
43 /* Case 1.  The full set of headers used with -ansi really work, use them.    */
44 #if defined(LIBCISANSI)||defined(SUNOS)||(defined(ANYSYSV)&&(defined(__m88k)||\
45 					  defined(__i386_)||defined(__m68k)))
46 #  ifdef __VXWORKS
47 #    include <vxWorks.h>
48 #    undef BSD
49 #    undef MSW
50 #    define _EXTENSION_POSIX_REENTRANT 1
51 #  endif
52 #  include <sys/types.h>
53 #  include <sys/stat.h>
54 #if defined(SUNOS)
55 #  include <sys/time.h>
56 #endif
57 #  include <time.h>
58 #  include <stdlib.h>
59 #  include <stddef.h>
60 #  include <unistd.h>		/* POSIX: close(),lseek(),read(),write() */
61 #  include <fcntl.h>		/* POSIX: creat(), open() */
62 #if !defined(CHORUS) && !defined (__OSE)
63 #  include <sys/times.h>	/* added for fortimes.c */
64 #endif
65 
66 /* Case 2.  Only use default headers provided by GHS (/usr/include/ansi) */
67 #elif defined(CROSSUNIX)||!defined(ANYUNIX)
68 #    include <stdlib.h>
69 #    include <time.h>
70 #if defined(ANYBSD)
71 typedef long unsigned ino_t;	/* BSD and System V.4 */
72 #else
73 typedef unsigned short ino_t;	/* System V.3 */
74 #endif
75 #if defined(ANYSYSV4)
76 typedef long dev_t;
77 #define __misc_t	long
78 #else
79 typedef short dev_t;
80 #define __misc_t	short
81 #endif
82 
83 #if defined(__INTEGRITY)
84 /* off_t defined in <sys/types.h> */
85 #elif defined(__INTEGRITY_SHARED_LIBS)
86 #  if defined(__LLONG_BIT) && (__LLONG_BIT == 64)
87    typedef long long    off_t;
88 #  else
89 #    error "off_t should be a signed 64bit type"
90 #  endif
91 #else
92 typedef long off_t;
93 #endif
94 
95 /*#include <sys/stat.h> */
96 struct stat {
97     dev_t	st_dev;
98 #ifdef SOLARIS20
99     long	st_pad[3];
100 #endif
101     ino_t	st_ino;
102     __misc_t    st_mode;
103     __misc_t	dummy1[4];	/* mode, nlink, uid, gid, rdev */
104 #ifdef SOLARIS20
105     long	st_pad2[2];
106 #endif
107     off_t	st_size;
108 #ifdef SOLARIS20
109     long	dummy[19];
110 #else
111     long	dummy[16];
112 #endif
113 };
114 
115 /*#include <sys/time.h>*/
116 #if !defined(__INTEGRITY)
117 /* UNIX Structure representing time since epoch*/
118 struct timeval {
119     long tv_sec;		/* seconds */
120     long tv_usec;		/* fractional microseconds */
121 };
122 #endif
123 
124 /*#include <sys/times.h>*/
125 struct tms {
126     clock_t tms_utime;		/* user time */
127     clock_t tms_stime;		/* system time */
128     clock_t tms_cutime;		/* user time of all children */
129     clock_t tms_cstime;		/* system time of all children */
130 };
131 
132 /*#include <fcntl.h>*/
133 /* flags for open */
134 #define O_RDONLY        0	/* open for reading only */
135 #define O_WRONLY        1	/* open for writing only */
136 #define O_RDWR          2	/* open for reading or writing */
137 #define O_APPEND        8 	/* always write at the end of the file	*/
138 /* Use non-zero values for CROSSUNIX	*/
139 /* These values are consistent with numerous SysV and BSD variants, but */
140 /* are not implemented in the default stand-alone libind.a routines.	*/
141 #if defined(__INTEGRITY_SHARED_LIBS) || (defined(ANYBSD) && !defined(ANYSYSV))
142 /* Right for SUNOSv4, Tek, DecStation, ultrix, alpha, NeXT */
143 #define O_CREAT         0x200	/* create the file if it doesn't exist	*/
144 #define O_TRUNC         0x400	/* empty the file if in O_WRONLY or O_RDWR */
145 #define O_EXCL          0x800	/* fail if O_CREAT and file exists	*/
146 #else
147 /* Right for solaris2, m68030, m88000, AUX, SCO, MIPS, avion, sgi  */
148 #define O_CREAT         0x100	/* create the file if it doesn't exist	*/
149 #define O_TRUNC         0x200	/* empty the file if in O_WRONLY or O_RDWR */
150 #define O_EXCL          0x400	/* fail if O_CREAT and file exists	*/
151 #endif
152 /* In ind_stat.c we mention R_OK/W_OK/X_OK/F_OK but we don't provide any
153  * courtesy definitions of it. However cctempnm.c expects W_OK to have
154  * been defined; before 1994 it included unistd.h which on sun4 defines W_OK,
155  * but no longer does. In either case MSW is out of luck unless we make
156  * sure cctempnm.c will compile. Check for R_OK and if it has not been set
157  * by anyone else, define all four symbols:
158  */
159 #ifndef R_OK
160 #define R_OK 4
161 #define W_OK 2
162 #define X_OK 1
163 #define F_OK 0
164 #endif
165 
166 /* Prototypes for ind_io.c functions */
167 int close(int);
168 int creat(const char *, int);
169 int open(const char *, int, ...);
170 off_t lseek(int, off_t, int);
171 int read(int, void *, int);
172 int write(int, const void *, int);
173 /* ind_sgnl.c wants to call _exit(); */
174 void _Exit(int);
175 /* ind_trnc.c wants to call access(), unlink(), and rename() */
176 /* unlink() is a bit sticky; we would like to use remove() instead, BUT that */
177 /* is in libansi.a which is being linked in before us (libind.a/libsys.a)... */
178 int access(const char *, int);
179 int unlink(const char *);
180 int rename(const char *, const char *);
181 /* ccclock.c calls times() */
182 int times(struct tms *);
183 /* ccexecl.c calls execve(). */
184 int execve(const char *, char * const *, char **);
185 
186 #include <stddef.h>
187 void *sbrk(size_t);
188 
189 /* ccmalloc_heap.c calls sbrk() */
190 /* ccmktime.c calls __gh_timezone, and ind_time.c does internally */
191 extern int __gh_timezone(void);
192 
193 #include "indsyscl.h"
194 
195 /* Avoid using stdarg on SH - assembly coding of __ghs_syscall is
196  * strange/tedious and not worth the trouble. pDSP doesn't have 32-bit
197  * integers, it's doesn't need this check
198  */
199 #if defined(__SH7000) || defined(__NDR) || defined (__pDSP__) || defined(_ARC)
200 #pragma diag_suppress 1728
201 extern int __ghs_syscall();
202 #else
203 #if (__INT_BIT==32)
204 extern int __ghs_syscall(int, ...);
205 #elif (__LONG_BIT==32)
206 extern long __ghs_syscall(long, ...);
207 #else
208 #error "A 32-bit data type is necessary for the prototype of __ghs_syscall"
209 #endif
210 #endif
211 
212 /* Tektronics returns ETOOLONG if a file name is longer than its 256
213  * character limit. This value is mapped to ENOENT.
214  */
215 #if defined(TEKEM)
216 #define ETOOLONG   63
217 #endif
218 
219 /* Case 3.  Use conflicting headers from /usr/include AND /usr/include/ansi   */
220 /*	    This case is being phased out.  see case 1 for a better solution */
221 #else	/* ANYUNIX */
222 /*
223  * The typedefs in GHS (Ansi) headers and in Unix headers frequently
224  * conflict.  Suppress specific typedefs which we will never use
225  * when #including GHS headers.  Unfortunately, the header files
226  * themselves need these types, so #define size_t, etc. for the sake of
227  * the header files, and #undef them after.
228  */
229 #    define _SIZE_T
230 #    define size_t		unsigned int
231 #    define _PTRDIFF_T
232 #    define ptrdiff_t	int
233 #    define _WCHAR_T
234 #    define wchar_t		int
235 /* this was only here for FOPEN_MAX, which is only used in indOS.h.  We
236    can't #include stdio.h here, because GHS libraries are used with different
237    implementation of the stdio library.  Moved the whole FOPEN_MAX logic back
238    into indOS.c
239     %include "indstdio.h"
240 */
241 #    include <stdlib.h>
242 #    undef _SIZE_T
243 #    undef size_t
244 #    undef _PTRDIFF_T
245 #    undef ptrdiff_t
246 #    undef _WCHAR_T
247 #    undef wchar_t
248 #    include <sys/types.h>
249 #    include <sys/stat.h>
250 /* [JY] Wed Sep 16 16:14:44 PDT 1992. Sure is difficult to mix headers in C++ */
251 #ifdef __cplusplus
252 #    define open	__wrong__open__
253 #    include <fcntl.h>		/* only for cxfilebf.cxx */
254 #    undef open
255 #endif	/* __cplusplus */
256 #    if defined(ANYBSD) && ! defined(NEEDTZSET)
257 #      define _CLOCK_T
258 #      define _TIME_T
259 #      include <sys/time.h>
260 #      undef _CLOCK_T
261 #      undef _TIME_T
262 #    endif		/* ANYBSD and not NEEDTZSET */
263 #    include <sys/times.h> /* [JY] Fri Jun  4 15:07 1993 added for fortimes.c */
264 /* [JY] Fri Jul 30 15:44:09 PDT 1993.  ap30 88000 host needs these.  */
265     int close(int);
266     int creat(const char *, int);
267     int open(const char *, int, ...);
268     long lseek(int, long, int);
269     int read(int, void *, int);
270     int write(int, const void *, int);
271 /* End Of New Code */
272 
273 #endif	/* ANYUNIX */
274 
275 #ifndef NULL
276 #define NULL ((void*)0)
277 #endif
278 
279 int __gh_timezone(void); /* [JY] Thu Aug  1 17:55:55 PDT 1996 */
280 
281 #ifndef CLK_TCK			/* header for this varies between systems */
282 #define CLK_TCK	60		/* should be sysconf(_SC_CLK_TCK) on POSIX */
283 #endif
284 #ifndef CLOCKS_PER_SEC
285 #define CLOCKS_PER_SEC	1000000
286 #endif
287 
288 #if defined(__OSE)
289 struct tms {
290     clock_t tms_utime;          /* user time */
291     clock_t tms_stime;          /* system time */
292     clock_t tms_cutime;         /* user time of all children */
293     clock_t tms_cstime;         /* system time of all children */
294 };
295 /* ccclock.c wants to call times() */
296 int times(struct tms *);
297 /* ccexecl.c wants to call execve(). */
298 int execve(char *, char **, char **);
299 /* ccmalloc.c needs to call sbrk() */
300 void *sbrk(int);
301 /* ccmktime.c wants to call __gh_timezone, and ind_time.c does internally */
302 extern int __gh_timezone(void);
303 #endif /* __OSE */
304 
305 
306 
307 #ifdef __cplusplus		/* If C++ compiler, use C linkage */
308 }
309 #endif
310 
311