2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: tclUnixPort.h /main/2 1996/08/08 14:46:57 cde-hp $ */
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.
36 * Much of the material in this file was originally contributed
37 * by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
39 * Copyright (c) 1991-1994 The Regents of the University of California.
40 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
42 * See the file "license.terms" for information on usage and redistribution
43 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
45 * SCCS: @(#) tclUnixPort.h 1.33 96/03/25 17:15:21
56 #ifdef HAVE_NET_ERRNO_H
57 # include <net/errno.h>
61 #include <sys/param.h>
62 #include <sys/types.h>
64 # include "../compat/dirent2.h"
67 # include "../compat/dirent.h"
73 #ifdef HAVE_SYS_SELECT_H
74 # include <sys/select.h>
77 #if TIME_WITH_SYS_TIME
78 # include <sys/time.h>
82 # include <sys/time.h>
88 # include <sys/wait.h>
93 # include "../compat/unistd.h"
97 * Socket support stuff: This likely needs more work to parameterize for
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() */
108 * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
112 # define O_NONBLOCK 0x80
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
122 # define NBIO_FLAG O_NONBLOCK
124 # define NBIO_FLAG O_NDELAY
128 * The default platform eol translation on Unix is TCL_TRANSLATE_LF:
131 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF
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.
142 * The type of the status returned by wait varies from UNIX system
143 * to UNIX system. The macro below defines it:
147 # define WAIT_STATUS_TYPE pid_t
149 #ifndef NO_UNION_WAIT
150 # define WAIT_STATUS_TYPE union wait
152 # define WAIT_STATUS_TYPE int
157 * Supply definitions for macros to query wait status, if not already
158 * defined in header files above.
162 # define WIFEXITED(stat) (((*((int *) &(stat))) & 0xff) == 0)
166 # define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
170 # define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
174 # define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f)
178 # define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xff) == 0177)
182 # define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff)
186 * Define constants for waitpid() system call if they aren't defined
187 * by a system header file.
198 * Supply macros for seek offsets, if they're not already provided by
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.
223 # include <sys/times.h>
224 # include <sys/param.h>
233 # ifdef HAVE_BSDGETTIMEOFDAY
234 # define gettimeofday BSDgettimeofday
238 #ifdef GETTOD_NOT_DECLARED
239 EXTERN int gettimeofday _ANSI_ARGS_((struct timeval *tp,
240 struct timezone *tzp));
244 * Define access mode constants if they aren't already defined.
261 * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
266 # define FD_CLOEXEC 1
270 * On systems without symbolic links (i.e. S_IFLNK isn't defined)
271 * define "lstat" to use "stat" instead.
279 * Define macros to query file type bits, if they're not already
285 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
287 # define S_ISREG(m) 0
292 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
294 # define S_ISDIR(m) 0
299 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
301 # define S_ISCHR(m) 0
306 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
308 # define S_ISBLK(m) 0
313 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
315 # define S_ISFIFO(m) 0
320 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
322 # define S_ISLNK(m) 0
327 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
329 # define S_ISSOCK(m) 0
334 * Make sure that MAXPATHLEN is defined.
339 # define MAXPATHLEN PATH_MAX
341 # define MAXPATHLEN 2048
346 * Make sure that L_tmpnam is defined.
350 # define L_tmpnam 100
354 * The following macro defines the type of the mask arguments to
359 # define SELECT_MASK fd_set
362 typedef long fd_mask;
365 # define SELECT_MASK void
367 # define SELECT_MASK int
372 * Define "NBBY" (number of bits per byte) if it's not already defined.
380 * The following macro defines the number of fd_masks in an fd_set:
385 # define FD_SETSIZE OPEN_MAX
387 # define FD_SETSIZE 256
390 #if !defined(howmany)
391 # define howmany(x, y) (((x)+((y)-1))/(y))
394 # define NFDBITS NBBY*sizeof(fd_mask)
396 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
399 * The following function is declared in tclInt.h but doesn't do anything
403 #define TclSetSystemEnv(a,b)
406 * The following implements the Unix method for exiting the process.
408 #define TclPlatformExit(status) exit(status)
411 * The following functions always succeeds under Unix.
414 #define TclHasSockets(interp) (TCL_OK)
415 #define TclHasPipes() (1)
418 * Variables provided by the C library:
421 #if defined(_sgi) || defined(__sgi)
422 #define environ _environ
424 extern char **environ;
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.
434 extern double strtod();
436 #endif /* _TCLUNIXPORT */