jpayne@69
|
1 /*
|
jpayne@69
|
2 * tclUnixPort.h --
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * This header file handles porting issues that occur because of
|
jpayne@69
|
5 * differences between systems. It reads in UNIX-related header files and
|
jpayne@69
|
6 * sets up UNIX-related macros for Tcl's UNIX core. It should be the only
|
jpayne@69
|
7 * file that contains #ifdefs to handle different flavors of UNIX. This
|
jpayne@69
|
8 * file sets up the union of all UNIX-related things needed by any of the
|
jpayne@69
|
9 * Tcl core files. This file depends on configuration #defines such as
|
jpayne@69
|
10 * NO_DIRENT_H that are set up by the "configure" script.
|
jpayne@69
|
11 *
|
jpayne@69
|
12 * Much of the material in this file was originally contributed by Karl
|
jpayne@69
|
13 * Lehenbauer, Mark Diekhans and Peter da Silva.
|
jpayne@69
|
14 *
|
jpayne@69
|
15 * Copyright (c) 1991-1994 The Regents of the University of California.
|
jpayne@69
|
16 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
|
jpayne@69
|
17 *
|
jpayne@69
|
18 * See the file "license.terms" for information on usage and redistribution of
|
jpayne@69
|
19 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
jpayne@69
|
20 */
|
jpayne@69
|
21
|
jpayne@69
|
22 #ifndef _TCLUNIXPORT
|
jpayne@69
|
23 #define _TCLUNIXPORT
|
jpayne@69
|
24
|
jpayne@69
|
25 /*
|
jpayne@69
|
26 *---------------------------------------------------------------------------
|
jpayne@69
|
27 * The following sets of #includes and #ifdefs are required to get Tcl to
|
jpayne@69
|
28 * compile under the various flavors of unix.
|
jpayne@69
|
29 *---------------------------------------------------------------------------
|
jpayne@69
|
30 */
|
jpayne@69
|
31
|
jpayne@69
|
32 #include <errno.h>
|
jpayne@69
|
33 #include <fcntl.h>
|
jpayne@69
|
34 #ifdef HAVE_NET_ERRNO_H
|
jpayne@69
|
35 # include <net/errno.h>
|
jpayne@69
|
36 #endif
|
jpayne@69
|
37 #include <pwd.h>
|
jpayne@69
|
38 #include <signal.h>
|
jpayne@69
|
39 #ifdef HAVE_SYS_PARAM_H
|
jpayne@69
|
40 # include <sys/param.h>
|
jpayne@69
|
41 #endif
|
jpayne@69
|
42 #include <sys/types.h>
|
jpayne@69
|
43 #ifdef USE_DIRENT2_H
|
jpayne@69
|
44 # include "../compat/dirent2.h"
|
jpayne@69
|
45 #else
|
jpayne@69
|
46 #ifdef NO_DIRENT_H
|
jpayne@69
|
47 # include "../compat/dirent.h"
|
jpayne@69
|
48 #else
|
jpayne@69
|
49 # include <dirent.h>
|
jpayne@69
|
50 #endif
|
jpayne@69
|
51 #endif
|
jpayne@69
|
52
|
jpayne@69
|
53 /*
|
jpayne@69
|
54 *---------------------------------------------------------------------------
|
jpayne@69
|
55 * Parameterize for 64-bit filesystem support.
|
jpayne@69
|
56 *---------------------------------------------------------------------------
|
jpayne@69
|
57 */
|
jpayne@69
|
58
|
jpayne@69
|
59 #ifdef HAVE_STRUCT_DIRENT64
|
jpayne@69
|
60 typedef struct dirent64 Tcl_DirEntry;
|
jpayne@69
|
61 # define TclOSreaddir readdir64
|
jpayne@69
|
62 #else
|
jpayne@69
|
63 typedef struct dirent Tcl_DirEntry;
|
jpayne@69
|
64 # define TclOSreaddir readdir
|
jpayne@69
|
65 #endif
|
jpayne@69
|
66 #ifdef HAVE_DIR64
|
jpayne@69
|
67 typedef DIR64 TclDIR;
|
jpayne@69
|
68 # define TclOSopendir opendir64
|
jpayne@69
|
69 # define TclOSrewinddir rewinddir64
|
jpayne@69
|
70 # define TclOSclosedir closedir64
|
jpayne@69
|
71 #else
|
jpayne@69
|
72 typedef DIR TclDIR;
|
jpayne@69
|
73 # define TclOSopendir opendir
|
jpayne@69
|
74 # define TclOSrewinddir rewinddir
|
jpayne@69
|
75 # define TclOSclosedir closedir
|
jpayne@69
|
76 #endif
|
jpayne@69
|
77
|
jpayne@69
|
78 #ifdef HAVE_TYPE_OFF64_T
|
jpayne@69
|
79 typedef off64_t Tcl_SeekOffset;
|
jpayne@69
|
80 # define TclOSseek lseek64
|
jpayne@69
|
81 # define TclOSopen open64
|
jpayne@69
|
82 #else
|
jpayne@69
|
83 typedef off_t Tcl_SeekOffset;
|
jpayne@69
|
84 # define TclOSseek lseek
|
jpayne@69
|
85 # define TclOSopen open
|
jpayne@69
|
86 #endif
|
jpayne@69
|
87
|
jpayne@69
|
88 #ifdef __CYGWIN__
|
jpayne@69
|
89 #ifdef __cplusplus
|
jpayne@69
|
90 extern "C" {
|
jpayne@69
|
91 #endif
|
jpayne@69
|
92 /* Make some symbols available without including <windows.h> */
|
jpayne@69
|
93 # define DWORD unsigned int
|
jpayne@69
|
94 # define CP_UTF8 65001
|
jpayne@69
|
95 # define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004
|
jpayne@69
|
96 # define HANDLE void *
|
jpayne@69
|
97 # define HINSTANCE void *
|
jpayne@69
|
98 # define SOCKET unsigned int
|
jpayne@69
|
99 # define WSAEWOULDBLOCK 10035
|
jpayne@69
|
100 typedef unsigned short WCHAR;
|
jpayne@69
|
101 #ifdef __clang__
|
jpayne@69
|
102 #pragma clang diagnostic push
|
jpayne@69
|
103 #pragma clang diagnostic ignored "-Wignored-attributes"
|
jpayne@69
|
104 #endif
|
jpayne@69
|
105 __declspec(dllimport) extern __stdcall int GetModuleHandleExW(unsigned int, const void *, void *);
|
jpayne@69
|
106 __declspec(dllimport) extern __stdcall int GetModuleFileNameW(void *, const void *, int);
|
jpayne@69
|
107 __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int, const void *, int,
|
jpayne@69
|
108 char *, int, const char *, void *);
|
jpayne@69
|
109 __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int, const char *, int,
|
jpayne@69
|
110 WCHAR *, int);
|
jpayne@69
|
111 __declspec(dllimport) extern __stdcall void OutputDebugStringW(const WCHAR *);
|
jpayne@69
|
112 __declspec(dllimport) extern __stdcall int IsDebuggerPresent(void);
|
jpayne@69
|
113 __declspec(dllimport) extern __stdcall int GetLastError(void);
|
jpayne@69
|
114 __declspec(dllimport) extern __stdcall int GetFileAttributesW(const WCHAR *);
|
jpayne@69
|
115 __declspec(dllimport) extern __stdcall int SetFileAttributesW(const WCHAR *, int);
|
jpayne@69
|
116 __declspec(dllimport) extern int cygwin_conv_path(int, const void *, void *, int);
|
jpayne@69
|
117 #ifdef __clang__
|
jpayne@69
|
118 #pragma clang diagnostic pop
|
jpayne@69
|
119 #endif
|
jpayne@69
|
120 # define timezone _timezone
|
jpayne@69
|
121 extern int TclOSstat(const char *name, void *statBuf);
|
jpayne@69
|
122 extern int TclOSlstat(const char *name, void *statBuf);
|
jpayne@69
|
123 #ifdef __cplusplus
|
jpayne@69
|
124 }
|
jpayne@69
|
125 #endif
|
jpayne@69
|
126 #elif defined(HAVE_STRUCT_STAT64) && !defined(__APPLE__)
|
jpayne@69
|
127 # define TclOSstat(name, buf) stat64(name, (struct stat64 *)buf)
|
jpayne@69
|
128 # define TclOSlstat(name,buf) lstat64(name, (struct stat64 *)buf)
|
jpayne@69
|
129 #else
|
jpayne@69
|
130 # define TclOSstat(name, buf) stat(name, (struct stat *)buf)
|
jpayne@69
|
131 # define TclOSlstat(name, buf) lstat(name, (struct stat *)buf)
|
jpayne@69
|
132 #endif
|
jpayne@69
|
133
|
jpayne@69
|
134 /*
|
jpayne@69
|
135 *---------------------------------------------------------------------------
|
jpayne@69
|
136 * Miscellaneous includes that might be missing.
|
jpayne@69
|
137 *---------------------------------------------------------------------------
|
jpayne@69
|
138 */
|
jpayne@69
|
139
|
jpayne@69
|
140 #include <sys/file.h>
|
jpayne@69
|
141 #ifdef HAVE_SYS_SELECT_H
|
jpayne@69
|
142 # include <sys/select.h>
|
jpayne@69
|
143 #endif
|
jpayne@69
|
144 #include <sys/stat.h>
|
jpayne@69
|
145 #ifdef TIME_WITH_SYS_TIME
|
jpayne@69
|
146 # include <sys/time.h>
|
jpayne@69
|
147 # include <time.h>
|
jpayne@69
|
148 #else
|
jpayne@69
|
149 #ifdef HAVE_SYS_TIME_H
|
jpayne@69
|
150 # include <sys/time.h>
|
jpayne@69
|
151 #else
|
jpayne@69
|
152 # include <time.h>
|
jpayne@69
|
153 #endif
|
jpayne@69
|
154 #endif
|
jpayne@69
|
155 #ifndef NO_SYS_WAIT_H
|
jpayne@69
|
156 # include <sys/wait.h>
|
jpayne@69
|
157 #endif
|
jpayne@69
|
158 #ifdef HAVE_INTTYPES_H
|
jpayne@69
|
159 # include <inttypes.h>
|
jpayne@69
|
160 #endif
|
jpayne@69
|
161 #include <limits.h>
|
jpayne@69
|
162 #ifdef HAVE_STDINT_H
|
jpayne@69
|
163 # include <stdint.h>
|
jpayne@69
|
164 #endif
|
jpayne@69
|
165 #ifdef HAVE_UNISTD_H
|
jpayne@69
|
166 # include <unistd.h>
|
jpayne@69
|
167 #else
|
jpayne@69
|
168 # include "../compat/unistd.h"
|
jpayne@69
|
169 #endif
|
jpayne@69
|
170
|
jpayne@69
|
171 extern int TclUnixSetBlockingMode(int fd, int mode);
|
jpayne@69
|
172
|
jpayne@69
|
173 #include <utime.h>
|
jpayne@69
|
174
|
jpayne@69
|
175 /*
|
jpayne@69
|
176 *---------------------------------------------------------------------------
|
jpayne@69
|
177 * Socket support stuff: This likely needs more work to parameterize for each
|
jpayne@69
|
178 * system.
|
jpayne@69
|
179 *---------------------------------------------------------------------------
|
jpayne@69
|
180 */
|
jpayne@69
|
181
|
jpayne@69
|
182 #include <sys/socket.h> /* struct sockaddr, SOCK_STREAM, ... */
|
jpayne@69
|
183 #ifndef NO_UNAME
|
jpayne@69
|
184 # include <sys/utsname.h> /* uname system call. */
|
jpayne@69
|
185 #endif
|
jpayne@69
|
186 #include <netinet/in.h> /* struct in_addr, struct sockaddr_in */
|
jpayne@69
|
187 #include <arpa/inet.h> /* inet_ntoa() */
|
jpayne@69
|
188 #include <netdb.h> /* getaddrinfo() */
|
jpayne@69
|
189 #ifdef NEED_FAKE_RFC2553
|
jpayne@69
|
190 # include "../compat/fake-rfc2553.h"
|
jpayne@69
|
191 #endif
|
jpayne@69
|
192
|
jpayne@69
|
193 /*
|
jpayne@69
|
194 *---------------------------------------------------------------------------
|
jpayne@69
|
195 * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we look
|
jpayne@69
|
196 * for an alternative definition. If no other alternative is available we use
|
jpayne@69
|
197 * a reasonable guess.
|
jpayne@69
|
198 *---------------------------------------------------------------------------
|
jpayne@69
|
199 */
|
jpayne@69
|
200
|
jpayne@69
|
201 #ifndef NO_FLOAT_H
|
jpayne@69
|
202 # include <float.h>
|
jpayne@69
|
203 #else
|
jpayne@69
|
204 #ifndef NO_VALUES_H
|
jpayne@69
|
205 # include <values.h>
|
jpayne@69
|
206 #endif
|
jpayne@69
|
207 #endif
|
jpayne@69
|
208
|
jpayne@69
|
209 #ifndef FLT_MAX
|
jpayne@69
|
210 # ifdef MAXFLOAT
|
jpayne@69
|
211 # define FLT_MAX MAXFLOAT
|
jpayne@69
|
212 # else
|
jpayne@69
|
213 # define FLT_MAX 3.402823466E+38F
|
jpayne@69
|
214 # endif
|
jpayne@69
|
215 #endif
|
jpayne@69
|
216 #ifndef FLT_MIN
|
jpayne@69
|
217 # ifdef MINFLOAT
|
jpayne@69
|
218 # define FLT_MIN MINFLOAT
|
jpayne@69
|
219 # else
|
jpayne@69
|
220 # define FLT_MIN 1.175494351E-38F
|
jpayne@69
|
221 # endif
|
jpayne@69
|
222 #endif
|
jpayne@69
|
223
|
jpayne@69
|
224 /*
|
jpayne@69
|
225 *---------------------------------------------------------------------------
|
jpayne@69
|
226 * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
|
jpayne@69
|
227 *---------------------------------------------------------------------------
|
jpayne@69
|
228 */
|
jpayne@69
|
229
|
jpayne@69
|
230 #ifndef O_NONBLOCK
|
jpayne@69
|
231 # define O_NONBLOCK 0x80
|
jpayne@69
|
232 #endif
|
jpayne@69
|
233
|
jpayne@69
|
234 /*
|
jpayne@69
|
235 *---------------------------------------------------------------------------
|
jpayne@69
|
236 * The type of the status returned by wait varies from UNIX system to UNIX
|
jpayne@69
|
237 * system. The macro below defines it:
|
jpayne@69
|
238 *---------------------------------------------------------------------------
|
jpayne@69
|
239 */
|
jpayne@69
|
240
|
jpayne@69
|
241 #ifdef _AIX
|
jpayne@69
|
242 # define WAIT_STATUS_TYPE pid_t
|
jpayne@69
|
243 #else
|
jpayne@69
|
244 #ifndef NO_UNION_WAIT
|
jpayne@69
|
245 # define WAIT_STATUS_TYPE union wait
|
jpayne@69
|
246 #else
|
jpayne@69
|
247 # define WAIT_STATUS_TYPE int
|
jpayne@69
|
248 #endif
|
jpayne@69
|
249 #endif
|
jpayne@69
|
250
|
jpayne@69
|
251 /*
|
jpayne@69
|
252 *---------------------------------------------------------------------------
|
jpayne@69
|
253 * Supply definitions for macros to query wait status, if not already defined
|
jpayne@69
|
254 * in header files above.
|
jpayne@69
|
255 *---------------------------------------------------------------------------
|
jpayne@69
|
256 */
|
jpayne@69
|
257
|
jpayne@69
|
258 #ifndef WIFEXITED
|
jpayne@69
|
259 # define WIFEXITED(stat) (((*((int *) &(stat))) & 0xFF) == 0)
|
jpayne@69
|
260 #endif
|
jpayne@69
|
261
|
jpayne@69
|
262 #ifndef WEXITSTATUS
|
jpayne@69
|
263 # define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xFF)
|
jpayne@69
|
264 #endif
|
jpayne@69
|
265
|
jpayne@69
|
266 #ifndef WIFSIGNALED
|
jpayne@69
|
267 # define WIFSIGNALED(stat) \
|
jpayne@69
|
268 (((*((int *) &(stat)))) && ((*((int *) &(stat))) \
|
jpayne@69
|
269 == ((*((int *) &(stat))) & 0x00FF)))
|
jpayne@69
|
270 #endif
|
jpayne@69
|
271
|
jpayne@69
|
272 #ifndef WTERMSIG
|
jpayne@69
|
273 # define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7F)
|
jpayne@69
|
274 #endif
|
jpayne@69
|
275
|
jpayne@69
|
276 #ifndef WIFSTOPPED
|
jpayne@69
|
277 # define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xFF) == 0177)
|
jpayne@69
|
278 #endif
|
jpayne@69
|
279
|
jpayne@69
|
280 #ifndef WSTOPSIG
|
jpayne@69
|
281 # define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xFF)
|
jpayne@69
|
282 #endif
|
jpayne@69
|
283
|
jpayne@69
|
284 /*
|
jpayne@69
|
285 *---------------------------------------------------------------------------
|
jpayne@69
|
286 * Define constants for waitpid() system call if they aren't defined by a
|
jpayne@69
|
287 * system header file.
|
jpayne@69
|
288 *---------------------------------------------------------------------------
|
jpayne@69
|
289 */
|
jpayne@69
|
290
|
jpayne@69
|
291 #ifndef WNOHANG
|
jpayne@69
|
292 # define WNOHANG 1
|
jpayne@69
|
293 #endif
|
jpayne@69
|
294 #ifndef WUNTRACED
|
jpayne@69
|
295 # define WUNTRACED 2
|
jpayne@69
|
296 #endif
|
jpayne@69
|
297
|
jpayne@69
|
298 /*
|
jpayne@69
|
299 *---------------------------------------------------------------------------
|
jpayne@69
|
300 * Supply macros for seek offsets, if they're not already provided by an
|
jpayne@69
|
301 * include file.
|
jpayne@69
|
302 *---------------------------------------------------------------------------
|
jpayne@69
|
303 */
|
jpayne@69
|
304
|
jpayne@69
|
305 #ifndef SEEK_SET
|
jpayne@69
|
306 # define SEEK_SET 0
|
jpayne@69
|
307 #endif
|
jpayne@69
|
308 #ifndef SEEK_CUR
|
jpayne@69
|
309 # define SEEK_CUR 1
|
jpayne@69
|
310 #endif
|
jpayne@69
|
311 #ifndef SEEK_END
|
jpayne@69
|
312 # define SEEK_END 2
|
jpayne@69
|
313 #endif
|
jpayne@69
|
314
|
jpayne@69
|
315 /*
|
jpayne@69
|
316 *---------------------------------------------------------------------------
|
jpayne@69
|
317 * The stuff below is needed by the "time" command. If this system has no
|
jpayne@69
|
318 * gettimeofday call, then must use times() instead.
|
jpayne@69
|
319 *---------------------------------------------------------------------------
|
jpayne@69
|
320 */
|
jpayne@69
|
321
|
jpayne@69
|
322 #ifdef NO_GETTOD
|
jpayne@69
|
323 # include <sys/times.h>
|
jpayne@69
|
324 #else
|
jpayne@69
|
325 # ifdef HAVE_BSDGETTIMEOFDAY
|
jpayne@69
|
326 # define gettimeofday BSDgettimeofday
|
jpayne@69
|
327 # endif
|
jpayne@69
|
328 #endif
|
jpayne@69
|
329
|
jpayne@69
|
330 #ifdef GETTOD_NOT_DECLARED
|
jpayne@69
|
331 extern int gettimeofday(struct timeval *tp,
|
jpayne@69
|
332 struct timezone *tzp);
|
jpayne@69
|
333 #endif
|
jpayne@69
|
334
|
jpayne@69
|
335 /*
|
jpayne@69
|
336 *---------------------------------------------------------------------------
|
jpayne@69
|
337 * Define access mode constants if they aren't already defined.
|
jpayne@69
|
338 *---------------------------------------------------------------------------
|
jpayne@69
|
339 */
|
jpayne@69
|
340
|
jpayne@69
|
341 #ifndef F_OK
|
jpayne@69
|
342 # define F_OK 00
|
jpayne@69
|
343 #endif
|
jpayne@69
|
344 #ifndef X_OK
|
jpayne@69
|
345 # define X_OK 01
|
jpayne@69
|
346 #endif
|
jpayne@69
|
347 #ifndef W_OK
|
jpayne@69
|
348 # define W_OK 02
|
jpayne@69
|
349 #endif
|
jpayne@69
|
350 #ifndef R_OK
|
jpayne@69
|
351 # define R_OK 04
|
jpayne@69
|
352 #endif
|
jpayne@69
|
353
|
jpayne@69
|
354 /*
|
jpayne@69
|
355 *---------------------------------------------------------------------------
|
jpayne@69
|
356 * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't already
|
jpayne@69
|
357 * defined.
|
jpayne@69
|
358 *---------------------------------------------------------------------------
|
jpayne@69
|
359 */
|
jpayne@69
|
360
|
jpayne@69
|
361 #ifndef FD_CLOEXEC
|
jpayne@69
|
362 # define FD_CLOEXEC 1
|
jpayne@69
|
363 #endif
|
jpayne@69
|
364
|
jpayne@69
|
365 /*
|
jpayne@69
|
366 *---------------------------------------------------------------------------
|
jpayne@69
|
367 * On systems without symbolic links (i.e. S_IFLNK isn't defined) define
|
jpayne@69
|
368 * "lstat" to use "stat" instead.
|
jpayne@69
|
369 *---------------------------------------------------------------------------
|
jpayne@69
|
370 */
|
jpayne@69
|
371
|
jpayne@69
|
372 #ifndef S_IFLNK
|
jpayne@69
|
373 # undef TclOSlstat
|
jpayne@69
|
374 # define lstat stat
|
jpayne@69
|
375 # define lstat64 stat64
|
jpayne@69
|
376 # define TclOSlstat TclOSstat
|
jpayne@69
|
377 #endif
|
jpayne@69
|
378
|
jpayne@69
|
379 /*
|
jpayne@69
|
380 *---------------------------------------------------------------------------
|
jpayne@69
|
381 * Define macros to query file type bits, if they're not already defined.
|
jpayne@69
|
382 *---------------------------------------------------------------------------
|
jpayne@69
|
383 */
|
jpayne@69
|
384
|
jpayne@69
|
385 #ifndef S_ISREG
|
jpayne@69
|
386 # ifdef S_IFREG
|
jpayne@69
|
387 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
jpayne@69
|
388 # else
|
jpayne@69
|
389 # define S_ISREG(m) 0
|
jpayne@69
|
390 # endif
|
jpayne@69
|
391 #endif /* !S_ISREG */
|
jpayne@69
|
392 #ifndef S_ISDIR
|
jpayne@69
|
393 # ifdef S_IFDIR
|
jpayne@69
|
394 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
jpayne@69
|
395 # else
|
jpayne@69
|
396 # define S_ISDIR(m) 0
|
jpayne@69
|
397 # endif
|
jpayne@69
|
398 #endif /* !S_ISDIR */
|
jpayne@69
|
399 #ifndef S_ISCHR
|
jpayne@69
|
400 # ifdef S_IFCHR
|
jpayne@69
|
401 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
jpayne@69
|
402 # else
|
jpayne@69
|
403 # define S_ISCHR(m) 0
|
jpayne@69
|
404 # endif
|
jpayne@69
|
405 #endif /* !S_ISCHR */
|
jpayne@69
|
406
|
jpayne@69
|
407 #ifndef S_ISBLK
|
jpayne@69
|
408 # ifdef S_IFBLK
|
jpayne@69
|
409 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
jpayne@69
|
410 # else
|
jpayne@69
|
411 # define S_ISBLK(m) 0
|
jpayne@69
|
412 # endif
|
jpayne@69
|
413 #endif /* !S_ISBLK */
|
jpayne@69
|
414
|
jpayne@69
|
415 #ifndef S_ISFIFO
|
jpayne@69
|
416 # ifdef S_IFIFO
|
jpayne@69
|
417 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
jpayne@69
|
418 # else
|
jpayne@69
|
419 # define S_ISFIFO(m) 0
|
jpayne@69
|
420 # endif
|
jpayne@69
|
421 #endif /* !S_ISFIFO */
|
jpayne@69
|
422
|
jpayne@69
|
423 #ifndef S_ISLNK
|
jpayne@69
|
424 # ifdef S_IFLNK
|
jpayne@69
|
425 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
jpayne@69
|
426 # else
|
jpayne@69
|
427 # define S_ISLNK(m) 0
|
jpayne@69
|
428 # endif
|
jpayne@69
|
429 #endif /* !S_ISLNK */
|
jpayne@69
|
430
|
jpayne@69
|
431 #ifndef S_ISSOCK
|
jpayne@69
|
432 # ifdef S_IFSOCK
|
jpayne@69
|
433 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
jpayne@69
|
434 # else
|
jpayne@69
|
435 # define S_ISSOCK(m) 0
|
jpayne@69
|
436 # endif
|
jpayne@69
|
437 #endif /* !S_ISSOCK */
|
jpayne@69
|
438
|
jpayne@69
|
439 /*
|
jpayne@69
|
440 *---------------------------------------------------------------------------
|
jpayne@69
|
441 * Make sure that MAXPATHLEN and MAXNAMLEN are defined.
|
jpayne@69
|
442 *---------------------------------------------------------------------------
|
jpayne@69
|
443 */
|
jpayne@69
|
444
|
jpayne@69
|
445 #ifndef MAXPATHLEN
|
jpayne@69
|
446 # ifdef PATH_MAX
|
jpayne@69
|
447 # define MAXPATHLEN PATH_MAX
|
jpayne@69
|
448 # else
|
jpayne@69
|
449 # define MAXPATHLEN 2048
|
jpayne@69
|
450 # endif
|
jpayne@69
|
451 #endif
|
jpayne@69
|
452
|
jpayne@69
|
453 #ifndef MAXNAMLEN
|
jpayne@69
|
454 # ifdef NAME_MAX
|
jpayne@69
|
455 # define MAXNAMLEN NAME_MAX
|
jpayne@69
|
456 # else
|
jpayne@69
|
457 # define MAXNAMLEN 255
|
jpayne@69
|
458 # endif
|
jpayne@69
|
459 #endif
|
jpayne@69
|
460
|
jpayne@69
|
461 /*
|
jpayne@69
|
462 *---------------------------------------------------------------------------
|
jpayne@69
|
463 * The following macro defines the type of the mask arguments to select:
|
jpayne@69
|
464 *---------------------------------------------------------------------------
|
jpayne@69
|
465 */
|
jpayne@69
|
466
|
jpayne@69
|
467 #ifndef NO_FD_SET
|
jpayne@69
|
468 # define SELECT_MASK fd_set
|
jpayne@69
|
469 #else /* NO_FD_SET */
|
jpayne@69
|
470 # ifndef _AIX
|
jpayne@69
|
471 typedef long fd_mask;
|
jpayne@69
|
472 # endif /* !AIX */
|
jpayne@69
|
473 # if defined(_IBMR2)
|
jpayne@69
|
474 # define SELECT_MASK void
|
jpayne@69
|
475 # else /* !defined(_IBMR2) */
|
jpayne@69
|
476 # define SELECT_MASK int
|
jpayne@69
|
477 # endif /* defined(_IBMR2) */
|
jpayne@69
|
478 #endif /* !NO_FD_SET */
|
jpayne@69
|
479
|
jpayne@69
|
480 /*
|
jpayne@69
|
481 *---------------------------------------------------------------------------
|
jpayne@69
|
482 * Define "NBBY" (number of bits per byte) if it's not already defined.
|
jpayne@69
|
483 *---------------------------------------------------------------------------
|
jpayne@69
|
484 */
|
jpayne@69
|
485
|
jpayne@69
|
486 #ifndef NBBY
|
jpayne@69
|
487 # define NBBY 8
|
jpayne@69
|
488 #endif
|
jpayne@69
|
489
|
jpayne@69
|
490 /*
|
jpayne@69
|
491 *---------------------------------------------------------------------------
|
jpayne@69
|
492 * The following macro defines the number of fd_masks in an fd_set:
|
jpayne@69
|
493 *---------------------------------------------------------------------------
|
jpayne@69
|
494 */
|
jpayne@69
|
495
|
jpayne@69
|
496 #ifndef FD_SETSIZE
|
jpayne@69
|
497 # ifdef OPEN_MAX
|
jpayne@69
|
498 # define FD_SETSIZE OPEN_MAX
|
jpayne@69
|
499 # else
|
jpayne@69
|
500 # define FD_SETSIZE 256
|
jpayne@69
|
501 # endif
|
jpayne@69
|
502 #endif /* FD_SETSIZE */
|
jpayne@69
|
503
|
jpayne@69
|
504 #ifndef howmany
|
jpayne@69
|
505 # define howmany(x, y) (((x)+((y)-1))/(y))
|
jpayne@69
|
506 #endif /* !defined(howmany) */
|
jpayne@69
|
507
|
jpayne@69
|
508 #ifndef NFDBITS
|
jpayne@69
|
509 # define NFDBITS NBBY*sizeof(fd_mask)
|
jpayne@69
|
510 #endif /* NFDBITS */
|
jpayne@69
|
511
|
jpayne@69
|
512 #define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
|
jpayne@69
|
513
|
jpayne@69
|
514 /*
|
jpayne@69
|
515 *---------------------------------------------------------------------------
|
jpayne@69
|
516 * Not all systems declare the errno variable in errno.h. so this file does it
|
jpayne@69
|
517 * explicitly. The list of system error messages also isn't generally declared
|
jpayne@69
|
518 * in a header file anywhere.
|
jpayne@69
|
519 *---------------------------------------------------------------------------
|
jpayne@69
|
520 */
|
jpayne@69
|
521
|
jpayne@69
|
522 #ifdef NO_ERRNO
|
jpayne@69
|
523 extern int errno;
|
jpayne@69
|
524 #endif /* NO_ERRNO */
|
jpayne@69
|
525
|
jpayne@69
|
526 /*
|
jpayne@69
|
527 *---------------------------------------------------------------------------
|
jpayne@69
|
528 * Not all systems declare all the errors that Tcl uses! Provide some
|
jpayne@69
|
529 * work-arounds...
|
jpayne@69
|
530 *---------------------------------------------------------------------------
|
jpayne@69
|
531 */
|
jpayne@69
|
532
|
jpayne@69
|
533 #ifndef EOVERFLOW
|
jpayne@69
|
534 # ifdef EFBIG
|
jpayne@69
|
535 # define EOVERFLOW EFBIG
|
jpayne@69
|
536 # else /* !EFBIG */
|
jpayne@69
|
537 # define EOVERFLOW EINVAL
|
jpayne@69
|
538 # endif /* EFBIG */
|
jpayne@69
|
539 #endif /* EOVERFLOW */
|
jpayne@69
|
540
|
jpayne@69
|
541 /*
|
jpayne@69
|
542 *---------------------------------------------------------------------------
|
jpayne@69
|
543 * Variables provided by the C library:
|
jpayne@69
|
544 *---------------------------------------------------------------------------
|
jpayne@69
|
545 */
|
jpayne@69
|
546
|
jpayne@69
|
547 #if defined(__APPLE__) && defined(__DYNAMIC__)
|
jpayne@69
|
548 # include <crt_externs.h>
|
jpayne@69
|
549 # define environ (*_NSGetEnviron())
|
jpayne@69
|
550 # define USE_PUTENV 1
|
jpayne@69
|
551 #else
|
jpayne@69
|
552 # if defined(_sgi) || defined(__sgi)
|
jpayne@69
|
553 # define environ _environ
|
jpayne@69
|
554 # endif
|
jpayne@69
|
555 extern char ** environ;
|
jpayne@69
|
556 #endif
|
jpayne@69
|
557
|
jpayne@69
|
558 /*
|
jpayne@69
|
559 *---------------------------------------------------------------------------
|
jpayne@69
|
560 * Darwin specifc configure overrides.
|
jpayne@69
|
561 *---------------------------------------------------------------------------
|
jpayne@69
|
562 */
|
jpayne@69
|
563
|
jpayne@69
|
564 #ifdef __APPLE__
|
jpayne@69
|
565
|
jpayne@69
|
566 /*
|
jpayne@69
|
567 *---------------------------------------------------------------------------
|
jpayne@69
|
568 * Support for fat compiles: configure runs only once for multiple architectures
|
jpayne@69
|
569 *---------------------------------------------------------------------------
|
jpayne@69
|
570 */
|
jpayne@69
|
571
|
jpayne@69
|
572 # if defined(__LP64__) && defined (NO_COREFOUNDATION_64)
|
jpayne@69
|
573 # undef HAVE_COREFOUNDATION
|
jpayne@69
|
574 # endif /* __LP64__ && NO_COREFOUNDATION_64 */
|
jpayne@69
|
575 # include <sys/cdefs.h>
|
jpayne@69
|
576 # ifdef __DARWIN_UNIX03
|
jpayne@69
|
577 # if __DARWIN_UNIX03
|
jpayne@69
|
578 # undef HAVE_PUTENV_THAT_COPIES
|
jpayne@69
|
579 # else
|
jpayne@69
|
580 # define HAVE_PUTENV_THAT_COPIES 1
|
jpayne@69
|
581 # endif
|
jpayne@69
|
582 # endif /* __DARWIN_UNIX03 */
|
jpayne@69
|
583
|
jpayne@69
|
584 /*
|
jpayne@69
|
585 *---------------------------------------------------------------------------
|
jpayne@69
|
586 * Include AvailabilityMacros.h here (when available) to ensure any symbolic
|
jpayne@69
|
587 * MAC_OS_X_VERSION_* constants passed on the command line are translated.
|
jpayne@69
|
588 *---------------------------------------------------------------------------
|
jpayne@69
|
589 */
|
jpayne@69
|
590
|
jpayne@69
|
591 # ifdef HAVE_AVAILABILITYMACROS_H
|
jpayne@69
|
592 # include <AvailabilityMacros.h>
|
jpayne@69
|
593 # endif
|
jpayne@69
|
594
|
jpayne@69
|
595 /*
|
jpayne@69
|
596 *---------------------------------------------------------------------------
|
jpayne@69
|
597 * Support for weak import.
|
jpayne@69
|
598 *---------------------------------------------------------------------------
|
jpayne@69
|
599 */
|
jpayne@69
|
600
|
jpayne@69
|
601 # ifdef HAVE_WEAK_IMPORT
|
jpayne@69
|
602 # if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED)
|
jpayne@69
|
603 # undef HAVE_WEAK_IMPORT
|
jpayne@69
|
604 # else
|
jpayne@69
|
605 # ifndef WEAK_IMPORT_ATTRIBUTE
|
jpayne@69
|
606 # define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import))
|
jpayne@69
|
607 # endif
|
jpayne@69
|
608 # endif
|
jpayne@69
|
609 # endif /* HAVE_WEAK_IMPORT */
|
jpayne@69
|
610
|
jpayne@69
|
611 /*
|
jpayne@69
|
612 *---------------------------------------------------------------------------
|
jpayne@69
|
613 * Support for MAC_OS_X_VERSION_MAX_ALLOWED define from AvailabilityMacros.h:
|
jpayne@69
|
614 * only use API available in the indicated OS version or earlier.
|
jpayne@69
|
615 *---------------------------------------------------------------------------
|
jpayne@69
|
616 */
|
jpayne@69
|
617
|
jpayne@69
|
618 # ifdef MAC_OS_X_VERSION_MAX_ALLOWED
|
jpayne@69
|
619 # if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__)
|
jpayne@69
|
620 # undef HAVE_COREFOUNDATION
|
jpayne@69
|
621 # endif
|
jpayne@69
|
622 # if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
|
jpayne@69
|
623 # undef HAVE_OSSPINLOCKLOCK
|
jpayne@69
|
624 # undef HAVE_PTHREAD_ATFORK
|
jpayne@69
|
625 # undef HAVE_COPYFILE
|
jpayne@69
|
626 # endif
|
jpayne@69
|
627 # if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
|
jpayne@69
|
628 # ifdef TCL_THREADS
|
jpayne@69
|
629 /* prior to 10.3, realpath is not threadsafe, c.f. bug 711232 */
|
jpayne@69
|
630 # define NO_REALPATH 1
|
jpayne@69
|
631 # endif
|
jpayne@69
|
632 # undef HAVE_LANGINFO
|
jpayne@69
|
633 # endif
|
jpayne@69
|
634 # endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
|
jpayne@69
|
635 # if defined(HAVE_COREFOUNDATION) && defined(__LP64__) && \
|
jpayne@69
|
636 defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
jpayne@69
|
637 # warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5."
|
jpayne@69
|
638 # endif
|
jpayne@69
|
639
|
jpayne@69
|
640 /*
|
jpayne@69
|
641 *---------------------------------------------------------------------------
|
jpayne@69
|
642 * At present, using vfork() instead of fork() causes execve() to fail
|
jpayne@69
|
643 * intermittently on Darwin x86_64. rdar://4685553
|
jpayne@69
|
644 *---------------------------------------------------------------------------
|
jpayne@69
|
645 */
|
jpayne@69
|
646
|
jpayne@69
|
647 # if defined(__x86_64__) && !defined(FIXED_RDAR_4685553)
|
jpayne@69
|
648 # undef USE_VFORK
|
jpayne@69
|
649 # endif /* __x86_64__ */
|
jpayne@69
|
650 /* Workaround problems with vfork() when building with llvm-gcc-4.2 */
|
jpayne@69
|
651 # if defined (__llvm__) && \
|
jpayne@69
|
652 (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 2 || \
|
jpayne@69
|
653 (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0))))
|
jpayne@69
|
654 # undef USE_VFORK
|
jpayne@69
|
655 # endif /* __llvm__ */
|
jpayne@69
|
656 #endif /* __APPLE__ */
|
jpayne@69
|
657
|
jpayne@69
|
658 /*
|
jpayne@69
|
659 *---------------------------------------------------------------------------
|
jpayne@69
|
660 * The following macros and declarations represent the interface between
|
jpayne@69
|
661 * generic and unix-specific parts of Tcl. Some of the macros may override
|
jpayne@69
|
662 * functions declared in tclInt.h.
|
jpayne@69
|
663 *---------------------------------------------------------------------------
|
jpayne@69
|
664 */
|
jpayne@69
|
665
|
jpayne@69
|
666 /*
|
jpayne@69
|
667 * The default platform eol translation on Unix is TCL_TRANSLATE_LF.
|
jpayne@69
|
668 */
|
jpayne@69
|
669
|
jpayne@69
|
670 #ifdef DJGPP
|
jpayne@69
|
671 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF
|
jpayne@69
|
672 typedef int socklen_t;
|
jpayne@69
|
673 #else
|
jpayne@69
|
674 #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF
|
jpayne@69
|
675 #endif
|
jpayne@69
|
676
|
jpayne@69
|
677 /*
|
jpayne@69
|
678 *---------------------------------------------------------------------------
|
jpayne@69
|
679 * The following macros have trivial definitions, allowing generic code to
|
jpayne@69
|
680 * address platform-specific issues.
|
jpayne@69
|
681 *---------------------------------------------------------------------------
|
jpayne@69
|
682 */
|
jpayne@69
|
683
|
jpayne@69
|
684 #define TclpReleaseFile(file) /* Nothing. */
|
jpayne@69
|
685
|
jpayne@69
|
686 /*
|
jpayne@69
|
687 *---------------------------------------------------------------------------
|
jpayne@69
|
688 * The following defines wrap the system memory allocation routines.
|
jpayne@69
|
689 *---------------------------------------------------------------------------
|
jpayne@69
|
690 */
|
jpayne@69
|
691
|
jpayne@69
|
692 #define TclpSysAlloc(size, isBin) malloc((size_t)(size))
|
jpayne@69
|
693 #define TclpSysFree(ptr) free((char *)(ptr))
|
jpayne@69
|
694 #define TclpSysRealloc(ptr, size) realloc((char *)(ptr), (size_t)(size))
|
jpayne@69
|
695
|
jpayne@69
|
696 /*
|
jpayne@69
|
697 *---------------------------------------------------------------------------
|
jpayne@69
|
698 * The following macros and declaration wrap the C runtime library functions.
|
jpayne@69
|
699 *---------------------------------------------------------------------------
|
jpayne@69
|
700 */
|
jpayne@69
|
701
|
jpayne@69
|
702 #define TclpExit exit
|
jpayne@69
|
703
|
jpayne@69
|
704 #ifdef TCL_THREADS
|
jpayne@69
|
705 # include <pthread.h>
|
jpayne@69
|
706 #endif /* TCL_THREADS */
|
jpayne@69
|
707
|
jpayne@69
|
708 /* FIXME - Hyper-enormous platform assumption! */
|
jpayne@69
|
709 #ifndef AF_INET6
|
jpayne@69
|
710 # define AF_INET6 10
|
jpayne@69
|
711 #endif
|
jpayne@69
|
712
|
jpayne@69
|
713 /*
|
jpayne@69
|
714 *---------------------------------------------------------------------------
|
jpayne@69
|
715 * Set of MT-safe implementations of some known-to-be-MT-unsafe library calls.
|
jpayne@69
|
716 * Instead of returning pointers to the static storage, those return pointers
|
jpayne@69
|
717 * to the TSD data.
|
jpayne@69
|
718 *---------------------------------------------------------------------------
|
jpayne@69
|
719 */
|
jpayne@69
|
720
|
jpayne@69
|
721 #include <pwd.h>
|
jpayne@69
|
722 #include <grp.h>
|
jpayne@69
|
723
|
jpayne@69
|
724 extern struct passwd * TclpGetPwNam(const char *name);
|
jpayne@69
|
725 extern struct group * TclpGetGrNam(const char *name);
|
jpayne@69
|
726 extern struct passwd * TclpGetPwUid(uid_t uid);
|
jpayne@69
|
727 extern struct group * TclpGetGrGid(gid_t gid);
|
jpayne@69
|
728 extern struct hostent * TclpGetHostByName(const char *name);
|
jpayne@69
|
729 extern struct hostent * TclpGetHostByAddr(const char *addr,
|
jpayne@69
|
730 int length, int type);
|
jpayne@69
|
731 extern void *TclpMakeTcpClientChannelMode(
|
jpayne@69
|
732 void *tcpSocket, int mode);
|
jpayne@69
|
733
|
jpayne@69
|
734 #endif /* _TCLUNIXPORT */
|
jpayne@69
|
735
|
jpayne@69
|
736 /*
|
jpayne@69
|
737 * Local Variables:
|
jpayne@69
|
738 * mode: c
|
jpayne@69
|
739 * c-basic-offset: 4
|
jpayne@69
|
740 * fill-column: 78
|
jpayne@69
|
741 * End:
|
jpayne@69
|
742 */
|