Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/unix/tclUnixPort.h @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 15.3 KB
Line 
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.65 2008/03/11 22:26:27 das Exp $
23 */
24
25#ifndef _TCLUNIXPORT
26#define _TCLUNIXPORT
27
28#ifndef MODULE_SCOPE
29#define MODULE_SCOPE extern
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
61typedef struct dirent64 Tcl_DirEntry;
62#   define TclOSreaddir         readdir64
63#else
64typedef struct dirent   Tcl_DirEntry;
65#   define TclOSreaddir         readdir
66#endif
67
68#ifdef HAVE_TYPE_OFF64_T
69typedef off64_t         Tcl_SeekOffset;
70#   define TclOSseek            lseek64
71#   define TclOSopen            open64
72#else
73typedef off_t           Tcl_SeekOffset;
74#   define TclOSseek            lseek
75#   define TclOSopen            open
76#endif
77
78#ifdef HAVE_STRUCT_STAT64
79#   define TclOSstat            stat64
80#   define TclOSlstat           lstat64
81#else
82#   define TclOSstat            stat
83#   define TclOSlstat           lstat
84#endif
85
86#include <sys/file.h>
87#ifdef HAVE_SYS_SELECT_H
88#   include <sys/select.h>
89#endif
90#include <sys/stat.h>
91#if TIME_WITH_SYS_TIME
92#   include <sys/time.h>
93#   include <time.h>
94#else
95#if HAVE_SYS_TIME_H
96#   include <sys/time.h>
97#else
98#   include <time.h>
99#endif
100#endif
101#ifndef NO_SYS_WAIT_H
102#   include <sys/wait.h>
103#endif
104#if HAVE_INTTYPES_H
105#   include <inttypes.h>
106#endif
107#if HAVE_STDINT_H
108#   include <stdint.h>
109#endif
110#ifdef HAVE_UNISTD_H
111#   include <unistd.h>
112#else
113#   include "../compat/unistd.h"
114#endif
115
116MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode);
117
118#include <utime.h>
119
120/*
121 * Socket support stuff: This likely needs more work to parameterize for
122 * each system.
123 */
124#include <sys/socket.h>         /* struct sockaddr, SOCK_STREAM, ... */
125#ifndef NO_UNAME
126#   include <sys/utsname.h>     /* uname system call. */
127#endif
128#include <netinet/in.h>         /* struct in_addr, struct sockaddr_in */
129#include <arpa/inet.h>          /* inet_ntoa() */
130#include <netdb.h>              /* gethostbyname() */
131
132/*
133 * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we
134 * look for an alternative definition.  If no other alternative is available
135 * we use a reasonable guess.
136 */
137
138#ifndef NO_FLOAT_H
139#   include <float.h>
140#else
141#ifndef NO_VALUES_H
142#   include <values.h>
143#endif
144#endif
145
146#ifndef FLT_MAX
147#   ifdef MAXFLOAT
148#       define FLT_MAX MAXFLOAT
149#   else
150#       define FLT_MAX 3.402823466E+38F
151#   endif
152#endif
153#ifndef FLT_MIN
154#   ifdef MINFLOAT
155#       define FLT_MIN MINFLOAT
156#   else
157#       define FLT_MIN 1.175494351E-38F
158#   endif
159#endif
160
161/*
162 * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
163 */
164
165#ifndef O_NONBLOCK
166#   define O_NONBLOCK 0x80
167#endif
168
169/*
170 * The type of the status returned by wait varies from UNIX system
171 * to UNIX system.  The macro below defines it:
172 */
173
174#ifdef _AIX
175#   define WAIT_STATUS_TYPE pid_t
176#else
177#ifndef NO_UNION_WAIT
178#   define WAIT_STATUS_TYPE union wait
179#else
180#   define WAIT_STATUS_TYPE int
181#endif
182#endif
183
184/*
185 * Supply definitions for macros to query wait status, if not already
186 * defined in header files above.
187 */
188
189#ifndef WIFEXITED
190#   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
191#endif
192
193#ifndef WEXITSTATUS
194#   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
195#endif
196
197#ifndef WIFSIGNALED
198#   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
199#endif
200
201#ifndef WTERMSIG
202#   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
203#endif
204
205#ifndef WIFSTOPPED
206#   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
207#endif
208
209#ifndef WSTOPSIG
210#   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
211#endif
212
213/*
214 * Define constants for waitpid() system call if they aren't defined
215 * by a system header file.
216 */
217
218#ifndef WNOHANG
219#   define WNOHANG 1
220#endif
221#ifndef WUNTRACED
222#   define WUNTRACED 2
223#endif
224
225/*
226 * Supply macros for seek offsets, if they're not already provided by
227 * an include file.
228 */
229
230#ifndef SEEK_SET
231#   define SEEK_SET 0
232#endif
233#ifndef SEEK_CUR
234#   define SEEK_CUR 1
235#endif
236#ifndef SEEK_END
237#   define SEEK_END 2
238#endif
239
240/*
241 * The stuff below is needed by the "time" command.  If this system has no
242 * gettimeofday call, then must use times() instead.
243 */
244
245#ifdef NO_GETTOD
246#   include <sys/times.h>
247#else
248#   ifdef HAVE_BSDGETTIMEOFDAY
249#       define gettimeofday BSDgettimeofday
250#   endif
251#endif
252
253#ifdef GETTOD_NOT_DECLARED
254EXTERN int              gettimeofday _ANSI_ARGS_((struct timeval *tp,
255                            struct timezone *tzp));
256#endif
257
258/*
259 * Define access mode constants if they aren't already defined.
260 */
261
262#ifndef F_OK
263#    define F_OK 00
264#endif
265#ifndef X_OK
266#    define X_OK 01
267#endif
268#ifndef W_OK
269#    define W_OK 02
270#endif
271#ifndef R_OK
272#    define R_OK 04
273#endif
274
275/*
276 * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
277 * already defined.
278 */
279
280#ifndef FD_CLOEXEC
281#   define FD_CLOEXEC 1
282#endif
283
284/*
285 * On systems without symbolic links (i.e. S_IFLNK isn't defined)
286 * define "lstat" to use "stat" instead.
287 */
288
289#ifndef S_IFLNK
290#   undef TclOSlstat
291#   define lstat        stat
292#   define lstat64      stat64
293#   define TclOSlstat   TclOSstat
294#endif
295
296/*
297 * Define macros to query file type bits, if they're not already
298 * defined.
299 */
300
301#ifndef S_ISREG
302#   ifdef S_IFREG
303#       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
304#   else
305#       define S_ISREG(m) 0
306#   endif
307#endif /* !S_ISREG */
308#ifndef S_ISDIR
309#   ifdef S_IFDIR
310#       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
311#   else
312#       define S_ISDIR(m) 0
313#   endif
314#endif /* !S_ISDIR */
315#ifndef S_ISCHR
316#   ifdef S_IFCHR
317#       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
318#   else
319#       define S_ISCHR(m) 0
320#   endif
321#endif /* !S_ISCHR */
322#ifndef S_ISBLK
323#   ifdef S_IFBLK
324#       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
325#   else
326#       define S_ISBLK(m) 0
327#   endif
328#endif /* !S_ISBLK */
329#ifndef S_ISFIFO
330#   ifdef S_IFIFO
331#       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
332#   else
333#       define S_ISFIFO(m) 0
334#   endif
335#endif /* !S_ISFIFO */
336#ifndef S_ISLNK
337#   ifdef S_IFLNK
338#       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
339#   else
340#       define S_ISLNK(m) 0
341#   endif
342#endif /* !S_ISLNK */
343#ifndef S_ISSOCK
344#   ifdef S_IFSOCK
345#       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
346#   else
347#       define S_ISSOCK(m) 0
348#   endif
349#endif /* !S_ISSOCK */
350
351/*
352 * Make sure that MAXPATHLEN and MAXNAMLEN are defined.
353 */
354
355#ifndef MAXPATHLEN
356#   ifdef PATH_MAX
357#       define MAXPATHLEN PATH_MAX
358#   else
359#       define MAXPATHLEN 2048
360#   endif
361#endif
362
363#ifndef MAXNAMLEN
364#   ifdef NAME_MAX
365#       define MAXNAMLEN NAME_MAX
366#   else
367#       define MAXNAMLEN 255
368#   endif
369#endif
370
371/*
372 * Make sure that L_tmpnam is defined.
373 */
374
375#ifndef L_tmpnam
376#   define L_tmpnam 100
377#endif
378
379/*
380 * The following macro defines the type of the mask arguments to
381 * select:
382 */
383
384#ifndef NO_FD_SET
385#   define SELECT_MASK fd_set
386#else /* NO_FD_SET */
387#   ifndef _AIX
388        typedef long fd_mask;
389#   endif /* !AIX */
390#   if defined(_IBMR2)
391#       define SELECT_MASK void
392#   else /* !defined(_IBMR2) */
393#       define SELECT_MASK int
394#   endif /* defined(_IBMR2) */
395#endif /* !NO_FD_SET */
396
397/*
398 * Define "NBBY" (number of bits per byte) if it's not already defined.
399 */
400
401#ifndef NBBY
402#   define NBBY 8
403#endif
404
405/*
406 * The following macro defines the number of fd_masks in an fd_set:
407 */
408
409#ifndef FD_SETSIZE
410#   ifdef OPEN_MAX
411#       define FD_SETSIZE OPEN_MAX
412#   else
413#       define FD_SETSIZE 256
414#   endif
415#endif /* FD_SETSIZE */
416#if !defined(howmany)
417#   define howmany(x, y) (((x)+((y)-1))/(y))
418#endif /* !defined(howmany) */
419#ifndef NFDBITS
420#   define NFDBITS NBBY*sizeof(fd_mask)
421#endif /* NFDBITS */
422#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
423
424/*
425 * Not all systems declare the errno variable in errno.h. so this
426 * file does it explicitly.  The list of system error messages also
427 * isn't generally declared in a header file anywhere.
428 */
429
430#ifdef NO_ERRNO
431extern int errno;
432#endif /* NO_ERRNO */
433
434/*
435 * Not all systems declare all the errors that Tcl uses!  Provide some
436 * work-arounds...
437 */
438
439#ifndef EOVERFLOW
440#   ifdef EFBIG
441#       define EOVERFLOW EFBIG
442#   else /* !EFBIG */
443#       define EOVERFLOW EINVAL
444#   endif /* EFBIG */
445#endif /* EOVERFLOW */
446
447/*
448 * Variables provided by the C library:
449 */
450
451#if defined(__APPLE__) && defined(__DYNAMIC__)
452#   include <crt_externs.h>
453#   define environ (*_NSGetEnviron())
454#   define USE_PUTENV 1
455#else
456#   if defined(_sgi) || defined(__sgi)
457#       define environ _environ
458#   endif
459extern char **environ;
460#endif
461
462/*
463 * There is no platform-specific panic routine for Unix in the Tcl internals.
464 */
465
466#define TclpPanic ((Tcl_PanicProc *) NULL)
467
468/*
469 * Darwin specifc configure overrides.
470 */
471
472#ifdef __APPLE__
473/*
474 * Support for fat compiles: configure runs only once for multiple architectures
475 */
476#   if defined(__LP64__) && defined (NO_COREFOUNDATION_64)
477#       undef HAVE_COREFOUNDATION
478#    endif /* __LP64__ && NO_COREFOUNDATION_64 */
479#   include <sys/cdefs.h>
480#   ifdef __DARWIN_UNIX03
481#       if __DARWIN_UNIX03
482#           undef HAVE_PUTENV_THAT_COPIES
483#       else
484#           define HAVE_PUTENV_THAT_COPIES 1
485#       endif
486#   endif /* __DARWIN_UNIX03 */
487/*
488 * The termios configure test program relies on the configure script being run
489 * from a terminal, which is not the case e.g. when configuring from Xcode.
490 * Since termios is known to be present on all Mac OS X releases since 10.0,
491 * override the configure defines for serial API here. [Bug 497147]
492 */
493#   define USE_TERMIOS 1
494#   undef  USE_TERMIO
495#   undef  USE_SGTTY
496/*
497 * Include AvailabilityMacros.h here (when available) to ensure any symbolic
498 * MAC_OS_X_VERSION_* constants passed on the command line are translated.
499 */
500#   ifdef HAVE_AVAILABILITYMACROS_H
501#       include <AvailabilityMacros.h>
502#   endif
503/*
504 * Support for weak import.
505 */
506#   ifdef HAVE_WEAK_IMPORT
507#       if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED)
508#           undef HAVE_WEAK_IMPORT
509#       else
510#           ifndef WEAK_IMPORT_ATTRIBUTE
511#               define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import))
512#           endif
513#       endif
514#   endif /* HAVE_WEAK_IMPORT */
515/*
516 * Support for MAC_OS_X_VERSION_MAX_ALLOWED define from AvailabilityMacros.h:
517 * only use API available in the indicated OS version or earlier.
518 */
519#   ifdef MAC_OS_X_VERSION_MAX_ALLOWED
520#       if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__)
521#           undef HAVE_COREFOUNDATION
522#       endif
523#       if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
524#           undef HAVE_OSSPINLOCKLOCK
525#           undef HAVE_PTHREAD_ATFORK
526#           undef HAVE_COPYFILE
527#       endif
528#       if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
529#           ifdef TCL_THREADS
530                /* prior to 10.3, realpath is not threadsafe, c.f. bug 711232 */
531#               define NO_REALPATH 1
532#           endif
533#           undef HAVE_LANGINFO
534#       endif
535#   endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
536#   if defined(HAVE_COREFOUNDATION) && defined(__LP64__) && \
537            defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050
538#       warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5."
539#   endif
540/*
541 * At present, using vfork() instead of fork() causes execve() to fail
542 * intermittently on Darwin x86_64. rdar://4685553
543 */
544#   if defined(__x86_64__) && !defined(FIXED_RDAR_4685553)
545#       undef USE_VFORK
546#   endif /* __x86_64__ */
547/* Workaround problems with vfork() when building with llvm-gcc-4.2 */
548#   if defined (__llvm__) && \
549            (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 2 || \
550            (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0))))
551#       undef USE_VFORK
552#   endif /* __llvm__ */
553#endif /* __APPLE__ */
554
555/*
556 *---------------------------------------------------------------------------
557 * The following macros and declarations represent the interface between
558 * generic and unix-specific parts of Tcl.  Some of the macros may override
559 * functions declared in tclInt.h.
560 *---------------------------------------------------------------------------
561 */
562
563/*
564 * The default platform eol translation on Unix is TCL_TRANSLATE_LF.
565 */
566
567#ifdef DJGPP
568#define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_CRLF
569typedef int socklen_t;
570#else
571#define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_LF
572#endif
573
574/*
575 * The following macros have trivial definitions, allowing generic code to
576 * address platform-specific issues.
577 */
578
579#define TclpGetPid(pid)         ((unsigned long) (pid))
580#define TclpReleaseFile(file)   /* Nothing. */
581
582/*
583 * The following defines wrap the system memory allocation routines.
584 */
585
586#define TclpSysAlloc(size, isBin)       malloc((size_t)size)
587#define TclpSysFree(ptr)                free((char*)ptr)
588#define TclpSysRealloc(ptr, size)       realloc((char*)ptr, (size_t)size)
589
590/*
591 * The following macros and declaration wrap the C runtime library
592 * functions.
593 */
594
595#define TclpExit                exit
596
597#ifdef TCL_THREADS
598EXTERN struct tm *      TclpLocaltime(CONST time_t *);
599EXTERN struct tm *      TclpGmtime(CONST time_t *);
600EXTERN char *           TclpInetNtoa(struct in_addr);
601/* #define localtime(x) TclpLocaltime(x)
602 * #define gmtime(x)    TclpGmtime(x)    */
603#   undef inet_ntoa
604#   define inet_ntoa(x) TclpInetNtoa(x)
605#   ifdef HAVE_PTHREAD_ATTR_GET_NP
606#       define TclpPthreadGetAttrs      pthread_attr_get_np
607#       ifdef ATTRGETNP_NOT_DECLARED
608/*
609 * Assume it is in pthread_np.h if it isn't in pthread.h. [Bug 1064882]
610 * We might need to revisit this in the future. :^(
611 */
612#           include <pthread.h>
613#           include <pthread_np.h>
614#       endif
615#   else
616#       ifdef HAVE_PTHREAD_GETATTR_NP
617#           define TclpPthreadGetAttrs  pthread_getattr_np
618#           ifdef GETATTRNP_NOT_DECLARED
619EXTERN int pthread_getattr_np _ANSI_ARGS_((pthread_t, pthread_attr_t *));
620#           endif
621#       endif /* HAVE_PTHREAD_GETATTR_NP */
622#   endif /* HAVE_PTHREAD_ATTR_GET_NP */
623#endif /* TCL_THREADS */
624
625/*
626 * Set of MT-safe implementations of some
627 * known-to-be-MT-unsafe library calls.
628 * Instead of returning pointers to the
629 * static storage, those return pointers
630 * to the TSD data.
631 */
632
633#include <pwd.h>
634#include <grp.h>
635
636MODULE_SCOPE struct passwd*  TclpGetPwNam(const char *name);
637MODULE_SCOPE struct group*   TclpGetGrNam(const char *name);
638MODULE_SCOPE struct passwd*  TclpGetPwUid(uid_t uid);
639MODULE_SCOPE struct group*   TclpGetGrGid(gid_t gid);
640MODULE_SCOPE struct hostent* TclpGetHostByName(const char *name);
641MODULE_SCOPE struct hostent* TclpGetHostByAddr(const char *addr, int length, int type);
642
643#endif /* _TCLUNIXPORT */
Note: See TracBrowser for help on using the repository browser.