Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtdocbook / tcl / tclUnixPort.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: tclUnixPort.h /main/2 1996/08/08 14:46:57 cde-hp $ */
24 /*
25  * tclUnixPort.h --
26  *
27  *      This header file handles porting issues that occur because
28  *      of differences between systems.  It reads in UNIX-related
29  *      header files and sets up UNIX-related macros for Tcl's UNIX
30  *      core.  It should be the only file that contains #ifdefs to
31  *      handle different flavors of UNIX.  This file sets up the
32  *      union of all UNIX-related things needed by any of the Tcl
33  *      core files.  This file depends on configuration #defines such
34  *      as NO_DIRENT_H that are set up by the "configure" script.
35  *
36  *      Much of the material in this file was originally contributed
37  *      by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
38  *
39  * Copyright (c) 1991-1994 The Regents of the University of California.
40  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
41  *
42  * See the file "license.terms" for information on usage and redistribution
43  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
44  *
45  * SCCS: @(#) tclUnixPort.h 1.33 96/03/25 17:15:21
46  */
47
48 #ifndef _TCLUNIXPORT
49 #define _TCLUNIXPORT
50
51 #ifndef _TCLINT
52 #   include "tclInt.h"
53 #endif
54 #include <errno.h>
55 #include <fcntl.h>
56 #ifdef HAVE_NET_ERRNO_H
57 #   include <net/errno.h>
58 #endif
59 #include <pwd.h>
60 #include <signal.h>
61 #include <sys/param.h>
62 #include <sys/types.h>
63 #ifdef USE_DIRENT2_H
64 #   include "../compat/dirent2.h"
65 #else
66 #   ifdef NO_DIRENT_H
67 #       include "../compat/dirent.h"
68 #   else
69 #       include <dirent.h>
70 #   endif
71 #endif
72 #include <sys/file.h>
73 #ifdef HAVE_SYS_SELECT_H
74 #   include <sys/select.h>
75 #endif
76 #include <sys/stat.h>
77 #if TIME_WITH_SYS_TIME
78 #   include <sys/time.h>
79 #   include <time.h>
80 #else
81 #   if HAVE_SYS_TIME_H
82 #       include <sys/time.h>
83 #   else
84 #       include <time.h>
85 #   endif
86 #endif
87 #ifndef NO_SYS_WAIT_H
88 #   include <sys/wait.h>
89 #endif
90 #ifdef HAVE_UNISTD_H
91 #   include <unistd.h>
92 #else
93 #   include "../compat/unistd.h"
94 #endif
95
96 /*
97  * Socket support stuff: This likely needs more work to parameterize for
98  * each system.
99  */
100
101 #include <sys/socket.h>         /* struct sockaddr, SOCK_STREAM, ... */
102 #include <sys/utsname.h>        /* uname system call. */
103 #include <netinet/in.h>         /* struct in_addr, struct sockaddr_in */
104 #include <arpa/inet.h>          /* inet_ntoa() */
105 #include <netdb.h>              /* gethostbyname() */
106
107 /*
108  * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
109  */
110
111 #ifndef O_NONBLOCK
112 #   define O_NONBLOCK 0x80
113 #endif
114
115 /*
116  * HPUX needs the flag O_NONBLOCK to get the right non-blocking I/O
117  * semantics, while most other systems need O_NDELAY.  Define the
118  * constant NBIO_FLAG to be one of these
119  */
120
121 #ifdef HPUX
122 #  define NBIO_FLAG O_NONBLOCK
123 #else
124 #  define NBIO_FLAG O_NDELAY
125 #endif
126
127 /*
128  * The default platform eol translation on Unix is TCL_TRANSLATE_LF:
129  */
130
131 #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_LF
132
133 /*
134  * Not all systems declare the errno variable in errno.h. so this
135  * file does it explicitly.  The list of system error messages also
136  * isn't generally declared in a header file anywhere.
137  */
138
139 extern int errno;
140
141 /*
142  * The type of the status returned by wait varies from UNIX system
143  * to UNIX system.  The macro below defines it:
144  */
145
146 #ifdef _AIX
147 #   define WAIT_STATUS_TYPE pid_t
148 #else
149 #ifndef NO_UNION_WAIT
150 #   define WAIT_STATUS_TYPE union wait
151 #else
152 #   define WAIT_STATUS_TYPE int
153 #endif
154 #endif
155
156 /*
157  * Supply definitions for macros to query wait status, if not already
158  * defined in header files above.
159  */
160
161 #ifndef WIFEXITED
162 #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
163 #endif
164
165 #ifndef WEXITSTATUS
166 #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
167 #endif
168
169 #ifndef WIFSIGNALED
170 #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
171 #endif
172
173 #ifndef WTERMSIG
174 #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
175 #endif
176
177 #ifndef WIFSTOPPED
178 #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
179 #endif
180
181 #ifndef WSTOPSIG
182 #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
183 #endif
184
185 /*
186  * Define constants for waitpid() system call if they aren't defined
187  * by a system header file.
188  */
189
190 #ifndef WNOHANG
191 #   define WNOHANG 1
192 #endif
193 #ifndef WUNTRACED
194 #   define WUNTRACED 2
195 #endif
196
197 /*
198  * Supply macros for seek offsets, if they're not already provided by
199  * an include file.
200  */
201
202 #ifndef SEEK_SET
203 #   define SEEK_SET 0
204 #endif
205
206 #ifndef SEEK_CUR
207 #   define SEEK_CUR 1
208 #endif
209
210 #ifndef SEEK_END
211 #   define SEEK_END 2
212 #endif
213
214 /*
215  * The stuff below is needed by the "time" command.  If this
216  * system has no gettimeofday call, then must use times and the
217  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
218  * Unfortunately, some systems only have HZ and no CLK_TCK, and
219  * some might not even have HZ.
220  */
221
222 #ifdef NO_GETTOD
223 #   include <sys/times.h>
224 #   include <sys/param.h>
225 #   ifndef CLK_TCK
226 #       ifdef HZ
227 #           define CLK_TCK HZ
228 #       else
229 #           define CLK_TCK 60
230 #       endif
231 #   endif
232 #else
233 #   ifdef HAVE_BSDGETTIMEOFDAY
234 #       define gettimeofday BSDgettimeofday
235 #   endif
236 #endif
237
238 #ifdef GETTOD_NOT_DECLARED
239 EXTERN int              gettimeofday _ANSI_ARGS_((struct timeval *tp,
240                             struct timezone *tzp));
241 #endif
242
243 /*
244  * Define access mode constants if they aren't already defined.
245  */
246
247 #ifndef F_OK
248 #    define F_OK 00
249 #endif
250 #ifndef X_OK
251 #    define X_OK 01
252 #endif
253 #ifndef W_OK
254 #    define W_OK 02
255 #endif
256 #ifndef R_OK
257 #    define R_OK 04
258 #endif
259
260 /*
261  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
262  * already defined.
263  */
264
265 #ifndef FD_CLOEXEC
266 #   define FD_CLOEXEC 1
267 #endif
268
269 /*
270  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
271  * define "lstat" to use "stat" instead.
272  */
273
274 #ifndef S_IFLNK
275 #   define lstat stat
276 #endif
277
278 /*
279  * Define macros to query file type bits, if they're not already
280  * defined.
281  */
282
283 #ifndef S_ISREG
284 #   ifdef S_IFREG
285 #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
286 #   else
287 #       define S_ISREG(m) 0
288 #   endif
289 # endif
290 #ifndef S_ISDIR
291 #   ifdef S_IFDIR
292 #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
293 #   else
294 #       define S_ISDIR(m) 0
295 #   endif
296 # endif
297 #ifndef S_ISCHR
298 #   ifdef S_IFCHR
299 #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
300 #   else
301 #       define S_ISCHR(m) 0
302 #   endif
303 # endif
304 #ifndef S_ISBLK
305 #   ifdef S_IFBLK
306 #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
307 #   else
308 #       define S_ISBLK(m) 0
309 #   endif
310 # endif
311 #ifndef S_ISFIFO
312 #   ifdef S_IFIFO
313 #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
314 #   else
315 #       define S_ISFIFO(m) 0
316 #   endif
317 # endif
318 #ifndef S_ISLNK
319 #   ifdef S_IFLNK
320 #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
321 #   else
322 #       define S_ISLNK(m) 0
323 #   endif
324 # endif
325 #ifndef S_ISSOCK
326 #   ifdef S_IFSOCK
327 #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
328 #   else
329 #       define S_ISSOCK(m) 0
330 #   endif
331 # endif
332
333 /*
334  * Make sure that MAXPATHLEN is defined.
335  */
336
337 #ifndef MAXPATHLEN
338 #   ifdef PATH_MAX
339 #       define MAXPATHLEN PATH_MAX
340 #   else
341 #       define MAXPATHLEN 2048
342 #   endif
343 #endif
344
345 /*
346  * Make sure that L_tmpnam is defined.
347  */
348
349 #ifndef L_tmpnam
350 #   define L_tmpnam 100
351 #endif
352
353 /*
354  * The following macro defines the type of the mask arguments to
355  * select:
356  */
357
358 #ifndef NO_FD_SET
359 #   define SELECT_MASK fd_set
360 #else
361 #   ifndef _AIX
362         typedef long fd_mask;
363 #   endif
364 #   if defined(_IBMR2)
365 #       define SELECT_MASK void
366 #   else
367 #       define SELECT_MASK int
368 #   endif
369 #endif
370
371 /*
372  * Define "NBBY" (number of bits per byte) if it's not already defined.
373  */
374
375 #ifndef NBBY
376 #   define NBBY 8
377 #endif
378
379 /*
380  * The following macro defines the number of fd_masks in an fd_set:
381  */
382
383 #ifndef FD_SETSIZE
384 #   ifdef OPEN_MAX
385 #       define FD_SETSIZE OPEN_MAX
386 #   else
387 #       define FD_SETSIZE 256
388 #   endif
389 #endif
390 #if !defined(howmany)
391 #   define howmany(x, y) (((x)+((y)-1))/(y))
392 #endif
393 #ifndef NFDBITS
394 #   define NFDBITS NBBY*sizeof(fd_mask)
395 #endif
396 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
397
398 /*
399  * The following function is declared in tclInt.h but doesn't do anything
400  * on Unix systems.
401  */
402
403 #define TclSetSystemEnv(a,b)
404
405 /*
406  * The following implements the Unix method for exiting the process.
407  */
408 #define TclPlatformExit(status) exit(status)
409
410 /*
411  * The following functions always succeeds under Unix.
412  */
413
414 #define TclHasSockets(interp) (TCL_OK)
415 #define TclHasPipes() (1)
416
417 /*
418  * Variables provided by the C library:
419  */
420
421 #if defined(_sgi) || defined(__sgi)
422 #define environ _environ
423 #endif
424 extern char **environ;
425
426 /*
427  * At present (12/91) not all stdlib.h implementations declare strtod.
428  * The declaration below is here to ensure that it's declared, so that
429  * the compiler won't take the default approach of assuming it returns
430  * an int.  There's no ANSI prototype for it because there would end
431  * up being too many conflicts with slightly-different prototypes.
432  */
433
434 extern double strtod();
435
436 #endif /* _TCLUNIXPORT */