4 * This header file handles porting issues that occur because
5 * of differences between systems. It reads in UNIX-related
6 * header files and sets up UNIX-related macros for Tcl's UNIX
7 * core. It should be the only file that contains #ifdefs to
8 * handle different flavors of UNIX. This file sets up the
9 * union of all UNIX-related things needed by any of the Tcl
10 * core files. This file depends on configuration #defines such
11 * as NO_DIRENT_H that are set up by the "configure" script.
13 * Much of the material in this file was originally contributed
14 * by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
16 * Copyright (c) 1991-1994 The Regents of the University of California.
17 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
19 * See the file "license.terms" for information on usage and redistribution
20 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
33 *---------------------------------------------------------------------------
34 * The following sets of #includes and #ifdefs are required to get Tcl to
35 * compile under the various flavors of unix.
36 *---------------------------------------------------------------------------
41 #ifdef HAVE_NET_ERRNO_H
42 # include <net/errno.h>
46 #ifdef HAVE_SYS_PARAM_H
47 # include <sys/param.h>
49 #include <sys/types.h>
51 # include "../compat/dirent2.h"
54 # include "../compat/dirent.h"
60 #ifdef HAVE_STRUCT_DIRENT64
61 typedef struct dirent64 Tcl_DirEntry;
62 # define TclOSreaddir readdir64
63 # define TclOSreaddir_r readdir64_r
65 typedef struct dirent Tcl_DirEntry;
66 # define TclOSreaddir readdir
67 # define TclOSreaddir_r readdir_r
70 #ifdef HAVE_TYPE_OFF64_T
71 typedef off64_t Tcl_SeekOffset;
72 # define TclOSseek lseek64
73 # define TclOSopen open64
75 typedef off_t Tcl_SeekOffset;
76 # define TclOSseek lseek
77 # define TclOSopen open
80 #ifdef HAVE_STRUCT_STAT64
81 # define TclOSstat stat64
82 # define TclOSlstat lstat64
84 # define TclOSstat stat
85 # define TclOSlstat lstat
88 #if !HAVE_STRTOLL && defined(TCL_WIDE_INT_TYPE) && !TCL_WIDE_INT_IS_LONG
89 EXTERN Tcl_WideInt strtoll _ANSI_ARGS_((CONST char *string,
90 char **endPtr, int base));
91 EXTERN Tcl_WideUInt strtoull _ANSI_ARGS_((CONST char *string,
92 char **endPtr, int base));
96 #ifdef HAVE_SYS_SELECT_H
97 # include <sys/select.h>
100 #if TIME_WITH_SYS_TIME
101 # include <sys/time.h>
105 # include <sys/time.h>
110 #ifndef NO_SYS_WAIT_H
111 # include <sys/wait.h>
116 # include "../compat/unistd.h"
120 * Not using the Posix fcntl(...,O_NONBLOCK,...) interface, instead
121 * we are using ioctl(..,FIONBIO,..).
124 # ifdef HAVE_SYS_FILIO_H
125 # include <sys/filio.h> /* For FIONBIO. */
128 # ifdef HAVE_SYS_IOCTL_H
129 # include <sys/ioctl.h> /* For FIONBIO. */
131 #endif /* USE_FIONBIO */
135 * Socket support stuff: This likely needs more work to parameterize for
139 #include <sys/socket.h> /* struct sockaddr, SOCK_STREAM, ... */
141 # include <sys/utsname.h> /* uname system call. */
143 #include <netinet/in.h> /* struct in_addr, struct sockaddr_in */
144 #include <arpa/inet.h> /* inet_ntoa() */
145 #include <netdb.h> /* gethostbyname() */
148 * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we
149 * look for an alternative definition. If no other alternative is available
150 * we use a reasonable guess.
163 # define FLT_MAX MAXFLOAT
165 # define FLT_MAX 3.402823466E+38F
170 # define FLT_MIN MINFLOAT
172 # define FLT_MIN 1.175494351E-38F
177 * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
181 # define O_NONBLOCK 0x80
185 * HPUX needs the flag O_NONBLOCK to get the right non-blocking I/O
186 * semantics, while most other systems need O_NDELAY. Define the
187 * constant NBIO_FLAG to be one of these
191 # define NBIO_FLAG O_NONBLOCK
193 # define NBIO_FLAG O_NDELAY
197 * The type of the status returned by wait varies from UNIX system
198 * to UNIX system. The macro below defines it:
202 # define WAIT_STATUS_TYPE pid_t
204 #ifndef NO_UNION_WAIT
205 # define WAIT_STATUS_TYPE union wait
207 # define WAIT_STATUS_TYPE int
212 * Supply definitions for macros to query wait status, if not already
213 * defined in header files above.
217 # define WIFEXITED(stat) (((*((int *) &(stat))) & 0xff) == 0)
221 # define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
225 # define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
229 # define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f)
233 # define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xff) == 0177)
237 # define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff)
241 * Define constants for waitpid() system call if they aren't defined
242 * by a system header file.
253 * Supply macros for seek offsets, if they're not already provided by
268 * The stuff below is needed by the "time" command. If this system has no
269 * gettimeofday call, then must use times and the CLK_TCK #define (from
270 * sys/param.h) to compute elapsed time. Unfortunately, some systems only
271 * have HZ and no CLK_TCK, and some might not even have HZ.
275 # include <sys/times.h>
276 # include <sys/param.h>
285 # ifdef HAVE_BSDGETTIMEOFDAY
286 # define gettimeofday BSDgettimeofday
290 #ifdef GETTOD_NOT_DECLARED
291 EXTERN int gettimeofday _ANSI_ARGS_((struct timeval *tp,
292 struct timezone *tzp));
296 * Define access mode constants if they aren't already defined.
313 * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
318 # define FD_CLOEXEC 1
322 * On systems without symbolic links (i.e. S_IFLNK isn't defined)
323 * define "lstat" to use "stat" instead.
329 # define lstat64 stat64
330 # define TclOSlstat TclOSstat
334 * Define macros to query file type bits, if they're not already
340 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
342 # define S_ISREG(m) 0
344 #endif /* !S_ISREG */
347 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
349 # define S_ISDIR(m) 0
351 #endif /* !S_ISDIR */
354 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
356 # define S_ISCHR(m) 0
358 #endif /* !S_ISCHR */
361 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
363 # define S_ISBLK(m) 0
365 #endif /* !S_ISBLK */
368 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
370 # define S_ISFIFO(m) 0
372 #endif /* !S_ISFIFO */
375 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
377 # define S_ISLNK(m) 0
379 #endif /* !S_ISLNK */
382 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
384 # define S_ISSOCK(m) 0
386 #endif /* !S_ISSOCK */
389 * Make sure that MAXPATHLEN is defined.
394 # define MAXPATHLEN PATH_MAX
396 # define MAXPATHLEN 2048
401 * Make sure that L_tmpnam is defined.
405 # define L_tmpnam 100
409 * The following macro defines the type of the mask arguments to
414 # define SELECT_MASK fd_set
415 #else /* NO_FD_SET */
417 typedef long fd_mask;
420 # define SELECT_MASK void
421 # else /* !defined(_IBMR2) */
422 # define SELECT_MASK int
423 # endif /* defined(_IBMR2) */
424 #endif /* !NO_FD_SET */
427 * Define "NBBY" (number of bits per byte) if it's not already defined.
435 * The following macro defines the number of fd_masks in an fd_set:
440 # define FD_SETSIZE OPEN_MAX
442 # define FD_SETSIZE 256
444 #endif /* FD_SETSIZE */
445 #if !defined(howmany)
446 # define howmany(x, y) (((x)+((y)-1))/(y))
447 #endif /* !defined(howmany) */
449 # define NFDBITS NBBY*sizeof(fd_mask)
451 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
454 * Not all systems declare the errno variable in errno.h. so this
455 * file does it explicitly. The list of system error messages also
456 * isn't generally declared in a header file anywhere.
462 * Not all systems declare all the errors that Tcl uses! Provide some
468 # define EOVERFLOW EFBIG
470 # define EOVERFLOW EINVAL
472 #endif /* EOVERFLOW */
475 * Variables provided by the C library:
478 #if defined(_sgi) || defined(__sgi) || (defined(__APPLE__) && defined(__DYNAMIC__))
479 # define environ _environ
481 extern char **environ;
484 * At present (12/91) not all stdlib.h implementations declare strtod.
485 * The declaration below is here to ensure that it's declared, so that
486 * the compiler won't take the default approach of assuming it returns
487 * an int. There's no ANSI prototype for it because there would end
488 * up being too many conflicts with slightly-different prototypes.
491 extern double strtod();
494 * There is no platform-specific panic routine for Unix in the Tcl internals.
497 #define TclpPanic ((Tcl_PanicProc *) NULL)
500 *---------------------------------------------------------------------------
501 * The following macros and declarations represent the interface between
502 * generic and unix-specific parts of Tcl. Some of the macros may override
503 * functions declared in tclInt.h.
504 *---------------------------------------------------------------------------
508 * The default platform eol translation on Unix is TCL_TRANSLATE_LF.
512 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF
514 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF
518 * The following macros have trivial definitions, allowing generic code to
519 * address platform-specific issues.
522 #define TclpGetPid(pid) ((unsigned long) (pid))
523 #define TclpReleaseFile(file) /* Nothing. */
526 * The following defines wrap the system memory allocation routines for
527 * use by tclAlloc.c. By default off unused on Unix.
531 # define TclpSysAlloc(size, isBin) malloc((size_t)size)
532 # define TclpSysFree(ptr) free((char*)ptr)
533 # define TclpSysRealloc(ptr, size) realloc((char*)ptr, (size_t)size)
537 * The following macros and declaration wrap the C runtime library
541 #define TclpExit exit
544 * Platform specific mutex definition used by memory allocators.
545 * These mutexes are statically allocated and explicitly initialized.
546 * Most modules do not use this, but instead use Tcl_Mutex types and
547 * Tcl_MutexLock and Tcl_MutexUnlock that are self-initializing.
552 typedef pthread_mutex_t TclpMutex;
553 EXTERN void TclpMutexInit _ANSI_ARGS_((TclpMutex *mPtr));
554 EXTERN void TclpMutexLock _ANSI_ARGS_((TclpMutex *mPtr));
555 EXTERN void TclpMutexUnlock _ANSI_ARGS_((TclpMutex *mPtr));
556 EXTERN Tcl_DirEntry * TclpReaddir(DIR *);
557 EXTERN struct tm * TclpLocaltime(time_t *);
558 EXTERN struct tm * TclpGmtime(time_t *);
559 EXTERN char * TclpInetNtoa(struct in_addr);
560 #define readdir(x) TclpReaddir(x)
561 #define localtime(x) TclpLocaltime(x)
562 #define gmtime(x) TclpGmtime(x)
563 #define inet_ntoa(x) TclpInetNtoa(x)
565 #define TclOSreaddir(x) TclpReaddir(x)
567 typedef int TclpMutex;
568 #define TclpMutexInit(a)
569 #define TclpMutexLock(a)
570 #define TclpMutexUnlock(a)
571 #endif /* TCL_THREADS */
573 #include "tclPlatDecls.h"
574 #include "tclIntPlatDecls.h"
576 #endif /* _TCLUNIXPORT */