OSDN Git Service

* configure.in: Fix for autoconf 2.5.
[pf3gnuchains/pf3gnuchains3x.git] / tcl / unix / tclUnixPort.h
1 /*
2  * tclUnixPort.h --
3  *
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.
12  *
13  *      Much of the material in this file was originally contributed
14  *      by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
15  *
16  * Copyright (c) 1991-1994 The Regents of the University of California.
17  * Copyright (c) 1994-1997 Sun Microsystems, Inc.
18  *
19  * See the file "license.terms" for information on usage and redistribution
20  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
21  *
22  * RCS: @(#) $Id$
23  */
24
25 #ifndef _TCLUNIXPORT
26 #define _TCLUNIXPORT
27
28 #ifndef _TCLINT
29 #   include "tclInt.h"
30 #endif
31
32 /*
33  *---------------------------------------------------------------------------
34  * The following sets of #includes and #ifdefs are required to get Tcl to
35  * compile under the various flavors of unix.
36  *---------------------------------------------------------------------------
37  */
38
39 #include <errno.h>
40 #include <fcntl.h>
41 #ifdef HAVE_NET_ERRNO_H
42 #   include <net/errno.h>
43 #endif
44 #include <pwd.h>
45 #include <signal.h>
46 #ifdef HAVE_SYS_PARAM_H
47 #   include <sys/param.h>
48 #endif
49 #include <sys/types.h>
50 #ifdef USE_DIRENT2_H
51 #   include "../compat/dirent2.h"
52 #else
53 #ifdef NO_DIRENT_H
54 #   include "../compat/dirent.h"
55 #else
56 #   include <dirent.h>
57 #endif
58 #endif
59
60 #ifdef HAVE_STRUCT_DIRENT64
61 typedef struct dirent64 Tcl_DirEntry;
62 #   define TclOSreaddir         readdir64
63 #   define TclOSreaddir_r       readdir64_r
64 #else
65 typedef struct dirent   Tcl_DirEntry;
66 #   define TclOSreaddir         readdir
67 #   define TclOSreaddir_r       readdir_r
68 #endif
69
70 #ifdef HAVE_TYPE_OFF64_T
71 typedef off64_t         Tcl_SeekOffset;
72 #   define TclOSseek            lseek64
73 #   define TclOSopen            open64
74 #else
75 typedef off_t           Tcl_SeekOffset;
76 #   define TclOSseek            lseek
77 #   define TclOSopen            open
78 #endif
79
80 #ifdef HAVE_STRUCT_STAT64
81 #   define TclOSstat            stat64
82 #   define TclOSlstat           lstat64
83 #else
84 #   define TclOSstat            stat
85 #   define TclOSlstat           lstat
86 #endif
87
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));
93 #endif
94
95 #include <sys/file.h>
96 #ifdef HAVE_SYS_SELECT_H
97 #   include <sys/select.h>
98 #endif
99 #include <sys/stat.h>
100 #if TIME_WITH_SYS_TIME
101 #   include <sys/time.h>
102 #   include <time.h>
103 #else
104 #if HAVE_SYS_TIME_H
105 #   include <sys/time.h>
106 #else
107 #   include <time.h>
108 #endif
109 #endif
110 #ifndef NO_SYS_WAIT_H
111 #   include <sys/wait.h>
112 #endif
113 #ifdef HAVE_UNISTD_H
114 #   include <unistd.h>
115 #else
116 #   include "../compat/unistd.h"
117 #endif
118 #ifdef  USE_FIONBIO
119     /*
120      * Not using the Posix fcntl(...,O_NONBLOCK,...) interface, instead
121      * we are using ioctl(..,FIONBIO,..).
122      */
123
124 #   ifdef HAVE_SYS_FILIO_H
125 #       include <sys/filio.h>   /* For FIONBIO. */
126 #   endif
127
128 #   ifdef HAVE_SYS_IOCTL_H
129 #       include <sys/ioctl.h>   /* For FIONBIO. */
130 #   endif
131 #endif  /* USE_FIONBIO */
132 #include <utime.h>
133
134 /*
135  * Socket support stuff: This likely needs more work to parameterize for
136  * each system.
137  */
138
139 #include <sys/socket.h>         /* struct sockaddr, SOCK_STREAM, ... */
140 #ifndef NO_UNAME
141 #   include <sys/utsname.h>     /* uname system call. */
142 #endif
143 #include <netinet/in.h>         /* struct in_addr, struct sockaddr_in */
144 #include <arpa/inet.h>          /* inet_ntoa() */
145 #include <netdb.h>              /* gethostbyname() */
146
147 /*
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.
151  */
152
153 #ifndef NO_FLOAT_H
154 #   include <float.h>
155 #else
156 #ifndef NO_VALUES_H
157 #   include <values.h>
158 #endif
159 #endif
160
161 #ifndef FLT_MAX
162 #   ifdef MAXFLOAT
163 #       define FLT_MAX MAXFLOAT
164 #   else
165 #       define FLT_MAX 3.402823466E+38F
166 #   endif
167 #endif
168 #ifndef FLT_MIN
169 #   ifdef MINFLOAT
170 #       define FLT_MIN MINFLOAT
171 #   else
172 #       define FLT_MIN 1.175494351E-38F
173 #   endif
174 #endif
175
176 /*
177  * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
178  */
179
180 #ifndef O_NONBLOCK
181 #   define O_NONBLOCK 0x80
182 #endif
183
184 /*
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
188  */
189
190 #ifdef HPUX
191 #  define NBIO_FLAG O_NONBLOCK
192 #else
193 #  define NBIO_FLAG O_NDELAY
194 #endif
195
196 /*
197  * The type of the status returned by wait varies from UNIX system
198  * to UNIX system.  The macro below defines it:
199  */
200
201 #ifdef _AIX
202 #   define WAIT_STATUS_TYPE pid_t
203 #else
204 #ifndef NO_UNION_WAIT
205 #   define WAIT_STATUS_TYPE union wait
206 #else
207 #   define WAIT_STATUS_TYPE int
208 #endif
209 #endif
210
211 /*
212  * Supply definitions for macros to query wait status, if not already
213  * defined in header files above.
214  */
215
216 #ifndef WIFEXITED
217 #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
218 #endif
219
220 #ifndef WEXITSTATUS
221 #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
222 #endif
223
224 #ifndef WIFSIGNALED
225 #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
226 #endif
227
228 #ifndef WTERMSIG
229 #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
230 #endif
231
232 #ifndef WIFSTOPPED
233 #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
234 #endif
235
236 #ifndef WSTOPSIG
237 #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
238 #endif
239
240 /*
241  * Define constants for waitpid() system call if they aren't defined
242  * by a system header file.
243  */
244
245 #ifndef WNOHANG
246 #   define WNOHANG 1
247 #endif
248 #ifndef WUNTRACED
249 #   define WUNTRACED 2
250 #endif
251
252 /*
253  * Supply macros for seek offsets, if they're not already provided by
254  * an include file.
255  */
256
257 #ifndef SEEK_SET
258 #   define SEEK_SET 0
259 #endif
260 #ifndef SEEK_CUR
261 #   define SEEK_CUR 1
262 #endif
263 #ifndef SEEK_END
264 #   define SEEK_END 2
265 #endif
266
267 /*
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.
272  */
273
274 #ifdef NO_GETTOD
275 #   include <sys/times.h>
276 #   include <sys/param.h>
277 #   ifndef CLK_TCK
278 #       ifdef HZ
279 #           define CLK_TCK HZ
280 #       else
281 #           define CLK_TCK 60
282 #       endif
283 #   endif
284 #else
285 #   ifdef HAVE_BSDGETTIMEOFDAY
286 #       define gettimeofday BSDgettimeofday
287 #   endif
288 #endif
289
290 #ifdef GETTOD_NOT_DECLARED
291 EXTERN int              gettimeofday _ANSI_ARGS_((struct timeval *tp,
292                             struct timezone *tzp));
293 #endif
294
295 /*
296  * Define access mode constants if they aren't already defined.
297  */
298
299 #ifndef F_OK
300 #    define F_OK 00
301 #endif
302 #ifndef X_OK
303 #    define X_OK 01
304 #endif
305 #ifndef W_OK
306 #    define W_OK 02
307 #endif
308 #ifndef R_OK
309 #    define R_OK 04
310 #endif
311
312 /*
313  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
314  * already defined.
315  */
316
317 #ifndef FD_CLOEXEC
318 #   define FD_CLOEXEC 1
319 #endif
320
321 /*
322  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
323  * define "lstat" to use "stat" instead.
324  */
325
326 #ifndef S_IFLNK
327 #   undef TclOSlstat
328 #   define lstat        stat
329 #   define lstat64      stat64
330 #   define TclOSlstat   TclOSstat
331 #endif
332
333 /*
334  * Define macros to query file type bits, if they're not already
335  * defined.
336  */
337
338 #ifndef S_ISREG
339 #   ifdef S_IFREG
340 #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
341 #   else
342 #       define S_ISREG(m) 0
343 #   endif
344 #endif /* !S_ISREG */
345 #ifndef S_ISDIR
346 #   ifdef S_IFDIR
347 #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
348 #   else
349 #       define S_ISDIR(m) 0
350 #   endif
351 #endif /* !S_ISDIR */
352 #ifndef S_ISCHR
353 #   ifdef S_IFCHR
354 #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
355 #   else
356 #       define S_ISCHR(m) 0
357 #   endif
358 #endif /* !S_ISCHR */
359 #ifndef S_ISBLK
360 #   ifdef S_IFBLK
361 #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
362 #   else
363 #       define S_ISBLK(m) 0
364 #   endif
365 #endif /* !S_ISBLK */
366 #ifndef S_ISFIFO
367 #   ifdef S_IFIFO
368 #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
369 #   else
370 #       define S_ISFIFO(m) 0
371 #   endif
372 #endif /* !S_ISFIFO */
373 #ifndef S_ISLNK
374 #   ifdef S_IFLNK
375 #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
376 #   else
377 #       define S_ISLNK(m) 0
378 #   endif
379 #endif /* !S_ISLNK */
380 #ifndef S_ISSOCK
381 #   ifdef S_IFSOCK
382 #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
383 #   else
384 #       define S_ISSOCK(m) 0
385 #   endif
386 #endif /* !S_ISSOCK */
387
388 /*
389  * Make sure that MAXPATHLEN is defined.
390  */
391
392 #ifndef MAXPATHLEN
393 #   ifdef PATH_MAX
394 #       define MAXPATHLEN PATH_MAX
395 #   else
396 #       define MAXPATHLEN 2048
397 #   endif
398 #endif
399
400 /*
401  * Make sure that L_tmpnam is defined.
402  */
403
404 #ifndef L_tmpnam
405 #   define L_tmpnam 100
406 #endif
407
408 /*
409  * The following macro defines the type of the mask arguments to
410  * select:
411  */
412
413 #ifndef NO_FD_SET
414 #   define SELECT_MASK fd_set
415 #else /* NO_FD_SET */
416 #   ifndef _AIX
417         typedef long fd_mask;
418 #   endif /* !AIX */
419 #   if defined(_IBMR2)
420 #       define SELECT_MASK void
421 #   else /* !defined(_IBMR2) */
422 #       define SELECT_MASK int
423 #   endif /* defined(_IBMR2) */
424 #endif /* !NO_FD_SET */
425
426 /*
427  * Define "NBBY" (number of bits per byte) if it's not already defined.
428  */
429
430 #ifndef NBBY
431 #   define NBBY 8
432 #endif
433
434 /*
435  * The following macro defines the number of fd_masks in an fd_set:
436  */
437
438 #ifndef FD_SETSIZE
439 #   ifdef OPEN_MAX
440 #       define FD_SETSIZE OPEN_MAX
441 #   else
442 #       define FD_SETSIZE 256
443 #   endif
444 #endif /* FD_SETSIZE */
445 #if !defined(howmany)
446 #   define howmany(x, y) (((x)+((y)-1))/(y))
447 #endif /* !defined(howmany) */
448 #ifndef NFDBITS
449 #   define NFDBITS NBBY*sizeof(fd_mask)
450 #endif /* NFDBITS */
451 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
452
453 /*
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.
457  */
458
459 extern int errno;
460
461 /*
462  * Not all systems declare all the errors that Tcl uses!  Provide some
463  * work-arounds...
464  */
465
466 #ifndef EOVERFLOW
467 #   ifdef EFBIG
468 #       define EOVERFLOW EFBIG
469 #   else /* !EFBIG */
470 #       define EOVERFLOW EINVAL
471 #   endif /* EFBIG */
472 #endif /* EOVERFLOW */
473
474 /*
475  * Variables provided by the C library:
476  */
477
478 #if defined(_sgi) || defined(__sgi) || (defined(__APPLE__) && defined(__DYNAMIC__))
479 #   define environ _environ
480 #endif
481 extern char **environ;
482
483 /*
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.
489  */
490
491 extern double strtod();
492
493 /*
494  * There is no platform-specific panic routine for Unix in the Tcl internals.
495  */
496
497 #define TclpPanic ((Tcl_PanicProc *) NULL)
498
499 /*
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  *---------------------------------------------------------------------------
505  */
506
507 /*
508  * The default platform eol translation on Unix is TCL_TRANSLATE_LF.
509  */
510
511 #ifdef DJGPP
512 #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_CRLF
513 #else
514 #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_LF
515 #endif
516
517 /*
518  * The following macros have trivial definitions, allowing generic code to 
519  * address platform-specific issues.
520  */
521
522 #define TclpGetPid(pid)         ((unsigned long) (pid))
523 #define TclpReleaseFile(file)   /* Nothing. */
524
525 /*
526  * The following defines wrap the system memory allocation routines for
527  * use by tclAlloc.c.  By default off unused on Unix.
528  */
529
530 #if USE_TCLALLOC
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)
534 #endif
535
536 /*
537  * The following macros and declaration wrap the C runtime library
538  * functions.
539  */
540
541 #define TclpExit                exit
542
543 /*
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.
548  */
549
550 #ifdef TCL_THREADS
551 #include <pthread.h>
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)
564 #undef TclOSreaddir
565 #define TclOSreaddir(x) TclpReaddir(x)
566 #else
567 typedef int TclpMutex;
568 #define TclpMutexInit(a)
569 #define TclpMutexLock(a)
570 #define TclpMutexUnlock(a)
571 #endif /* TCL_THREADS */
572
573 #include "tclPlatDecls.h"
574 #include "tclIntPlatDecls.h"
575
576 #endif /* _TCLUNIXPORT */