Debian Codegraph @

pTk/mTk/tclUnix/tclUnixPort.h

raw symbols SCIP
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: tclUnixPort.h,v 1.27.2.1 2003/05/13 08:41:26 das Exp $
23 */
24
25 #ifndef _TCLUNIXPORT
26 #define _TCLUNIXPORT
27
28 #ifndef _LANG
29 # include "Lang.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 and MAXNAMLEN are 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 #ifndef MAXNAMLEN
401 # ifdef NAME_MAX
402 # define MAXNAMLEN NAME_MAX
403 # else
404 # define MAXNAMLEN 255
405 # endif
406 #endif
407
408 /*
409 * Make sure that L_tmpnam is defined.
410 */
411
412 #ifndef L_tmpnam
413 # define L_tmpnam 100
414 #endif
415
416 /*
417 * The following macro defines the type of the mask arguments to
418 * select:
419 */
420
421 #ifndef NO_FD_SET
422 # define SELECT_MASK fd_set
423 #else /* NO_FD_SET */
424 # ifndef _AIX
425 typedef long fd_mask;
426 # endif /* !AIX */
427 # if defined(_IBMR2)
428 # define SELECT_MASK void
429 # else /* !defined(_IBMR2) */
430 # define SELECT_MASK int
431 # endif /* defined(_IBMR2) */
432 #endif /* !NO_FD_SET */
433
434 /*
435 * Define "NBBY" (number of bits per byte) if it's not already defined.
436 */
437
438 #ifndef NBBY
439 # define NBBY 8
440 #endif
441
442 /*
443 * The following macro defines the number of fd_masks in an fd_set:
444 */
445
446 #ifndef FD_SETSIZE
447 # ifdef OPEN_MAX
448 # define FD_SETSIZE OPEN_MAX
449 # else
450 # define FD_SETSIZE 256
451 # endif
452 #endif /* FD_SETSIZE */
453 #if !defined(howmany)
454 # define howmany(x, y) (((x)+((y)-1))/(y))
455 #endif /* !defined(howmany) */
456 #ifndef NFDBITS
457 # define NFDBITS NBBY*sizeof(fd_mask)
458 #endif /* NFDBITS */
459 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
460
461 /*
462 * Not all systems declare the errno variable in errno.h. so this
463 * file does it explicitly. The list of system error messages also
464 * isn't generally declared in a header file anywhere.
465 */
466
467 extern int errno;
468
469 /*
470 * Not all systems declare all the errors that Tcl uses! Provide some
471 * work-arounds...
472 */
473
474 #ifndef EOVERFLOW
475 # ifdef EFBIG
476 # define EOVERFLOW EFBIG
477 # else /* !EFBIG */
478 # define EOVERFLOW EINVAL
479 # endif /* EFBIG */
480 #endif /* EOVERFLOW */
481
482 /*
483 * Variables provided by the C library:
484 */
485
486 #if defined(_sgi) || defined(__sgi) || (defined(__APPLE__) && defined(__DYNAMIC__))
487 # define environ _environ
488 #endif
489 extern char **environ;
490
491 /*
492 * At present (12/91) not all stdlib.h implementations declare strtod.
493 * The declaration below is here to ensure that it's declared, so that
494 * the compiler won't take the default approach of assuming it returns
495 * an int. There's no ANSI prototype for it because there would end
496 * up being too many conflicts with slightly-different prototypes.
497 */
498
499 extern double strtod();
500
501 /*
502 * There is no platform-specific panic routine for Unix in the Tcl internals.
503 */
504
505 #define TclpPanic ((Tcl_PanicProc *) NULL)
506
507 /*
508 *---------------------------------------------------------------------------
509 * The following macros and declarations represent the interface between
510 * generic and unix-specific parts of Tcl. Some of the macros may override
511 * functions declared in tclInt.h.
512 *---------------------------------------------------------------------------
513 */
514
515 /*
516 * The default platform eol translation on Unix is TCL_TRANSLATE_LF.
517 */
518
519 #ifdef DJGPP
520 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF
521 #else
522 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF
523 #endif
524
525 /*
526 * The following macros have trivial definitions, allowing generic code to
527 * address platform-specific issues.
528 */
529
530 #define TclpGetPid(pid) ((unsigned long) (pid))
531 #define TclpReleaseFile(file) /* Nothing. */
532
533 /*
534 * The following defines wrap the system memory allocation routines for
535 * use by tclAlloc.c. By default off unused on Unix.
536 */
537
538 #if USE_TCLALLOC
539 # define TclpSysAlloc(size, isBin) malloc((size_t)size)
540 # define TclpSysFree(ptr) free((char*)ptr)
541 # define TclpSysRealloc(ptr, size) realloc((char*)ptr, (size_t)size)
542 #endif
543
544 /*
545 * The following macros and declaration wrap the C runtime library
546 * functions.
547 */
548
549 #define TclpExit exit
550
551 /*
552 * Platform specific mutex definition used by memory allocators.
553 * These mutexes are statically allocated and explicitly initialized.
554 * Most modules do not use this, but instead use Tcl_Mutex types and
555 * Tcl_MutexLock and Tcl_MutexUnlock that are self-initializing.
556 */
557
558 #ifdef TCL_THREADS
559 #include <pthread.h>
560 typedef pthread_mutex_t TclpMutex;
561 EXTERN void TclpMutexInit _ANSI_ARGS_((TclpMutex *mPtr));
562 EXTERN void TclpMutexLock _ANSI_ARGS_((TclpMutex *mPtr));
563 EXTERN void TclpMutexUnlock _ANSI_ARGS_((TclpMutex *mPtr));
564 EXTERN Tcl_DirEntry * TclpReaddir(DIR *);
565 EXTERN struct tm * TclpLocaltime(time_t *);
566 EXTERN struct tm * TclpGmtime(time_t *);
567 EXTERN char * TclpInetNtoa(struct in_addr);
568 #define readdir(x) TclpReaddir(x)
569 #define localtime(x) TclpLocaltime(x)
570 #define gmtime(x) TclpGmtime(x)
571 #define inet_ntoa(x) TclpInetNtoa(x)
572 #undef TclOSreaddir
573 #define TclOSreaddir(x) TclpReaddir(x)
574 #ifdef MAC_OSX_TCL
575 /*
576 * On Mac OS X, realpath is currently not
577 * thread safe, c.f. SF bug # 711232.
578 */
579 #define NO_REALPATH
580 #endif
581 #else
582 typedef int TclpMutex;
583 #define TclpMutexInit(a)
584 #define TclpMutexLock(a)
585 #define TclpMutexUnlock(a)
586 #endif /* TCL_THREADS */
587
588 #include "tclPlatDecls.h"
589 #include "tclIntPlatDecls.h"
590
591 #endif /* _TCLUNIXPORT */