OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [unix/] [tclUnixPort.h] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
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-1995 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.1.1.1 2002-01-16 10:25:37 markom Exp $
23
 */
24
 
25
#ifndef _TCLUNIXPORT
26
#define _TCLUNIXPORT
27
 
28
#ifndef _TCLINT
29
#   include "tclInt.h"
30
#endif
31
#include <errno.h>
32
#include <fcntl.h>
33
#ifdef HAVE_NET_ERRNO_H
34
#   include <net/errno.h>
35
#endif
36
#include <pwd.h>
37
#include <signal.h>
38
#include <sys/param.h>
39
#include <sys/types.h>
40
#ifdef USE_DIRENT2_H
41
#   include "../compat/dirent2.h"
42
#else
43
#   ifdef NO_DIRENT_H
44
#       include "../compat/dirent.h"
45
#   else
46
#       include <dirent.h>
47
#   endif
48
#endif
49
#include <sys/file.h>
50
#ifdef HAVE_SYS_SELECT_H
51
#   include <sys/select.h>
52
#endif
53
#include <sys/stat.h>
54
#if TIME_WITH_SYS_TIME
55
#   include <sys/time.h>
56
#   include <time.h>
57
#else
58
#   if HAVE_SYS_TIME_H
59
#       include <sys/time.h>
60
#   else
61
#       include <time.h>
62
#   endif
63
#endif
64
#ifndef NO_SYS_WAIT_H
65
#   include <sys/wait.h>
66
#endif
67
#ifdef HAVE_UNISTD_H
68
#   include <unistd.h>
69
#else
70
#   include "../compat/unistd.h"
71
#endif
72
#ifdef  USE_FIONBIO
73
 
74
    /*
75
     * Not using the Posix fcntl(...,O_NONBLOCK,...) interface, instead
76
     * we are using ioctl(..,FIONBIO,..).
77
     */
78
 
79
#   ifdef HAVE_SYS_FILIO_H
80
#       include <sys/filio.h>   /* For FIONBIO. */
81
#   endif
82
 
83
#   ifdef HAVE_SYS_IOCTL_H
84
#       include <sys/ioctl.h>   /* For FIONBIO. */
85
#   endif
86
#endif  /* USE_FIONBIO */
87
 
88
/*
89
 * Socket support stuff: This likely needs more work to parameterize for
90
 * each system.
91
 */
92
 
93
#include <sys/socket.h>         /* struct sockaddr, SOCK_STREAM, ... */
94
#ifndef NO_UNAME
95
#   include <sys/utsname.h>     /* uname system call. */
96
#endif
97
#include <netinet/in.h>         /* struct in_addr, struct sockaddr_in */
98
#include <arpa/inet.h>          /* inet_ntoa() */
99
#include <netdb.h>              /* gethostbyname() */
100
 
101
/*
102
 * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we
103
 * look for an alternative definition.  If no other alternative is available
104
 * we use a reasonable guess.
105
 */
106
 
107
#ifndef NO_FLOAT_H
108
#include <float.h>
109
#else
110
#   ifndef NO_VALUES_H
111
#       include <values.h>
112
#   endif
113
#endif
114
 
115
#ifndef FLT_MAX
116
#   ifdef MAXFLOAT
117
#       define FLT_MAX MAXFLOAT
118
#   else
119
#       define FLT_MAX 3.402823466E+38F
120
#   endif
121
#endif
122
#ifndef FLT_MIN
123
#   ifdef MINFLOAT
124
#       define FLT_MIN MINFLOAT
125
#   else
126
#       define FLT_MIN 1.175494351E-38F
127
#   endif
128
#endif
129
 
130
/*
131
 * NeXT doesn't define O_NONBLOCK, so #define it here if necessary.
132
 */
133
 
134
#ifndef O_NONBLOCK
135
#   define O_NONBLOCK 0x80
136
#endif
137
 
138
/*
139
 * HPUX needs the flag O_NONBLOCK to get the right non-blocking I/O
140
 * semantics, while most other systems need O_NDELAY.  Define the
141
 * constant NBIO_FLAG to be one of these
142
 */
143
 
144
#ifdef HPUX
145
#  define NBIO_FLAG O_NONBLOCK
146
#else
147
#  define NBIO_FLAG O_NDELAY
148
#endif
149
 
150
/*
151
 * The following defines denote malloc and free as the system calls
152
 * used to allocate new memory.  These defines are only used in the
153
 * file tclCkalloc.c.
154
 */
155
 
156
#define TclpAlloc(size)         malloc(size)
157
#define TclpFree(ptr)           free(ptr)
158
#define TclpRealloc(ptr, size)  realloc(ptr, size)
159
 
160
/*
161
 * The default platform eol translation on Unix is TCL_TRANSLATE_LF:
162
 */
163
 
164
#define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_LF
165
 
166
/*
167
 * Not all systems declare the errno variable in errno.h. so this
168
 * file does it explicitly.  The list of system error messages also
169
 * isn't generally declared in a header file anywhere.
170
 */
171
 
172
extern int errno;
173
 
174
/*
175
 * The type of the status returned by wait varies from UNIX system
176
 * to UNIX system.  The macro below defines it:
177
 */
178
 
179
#ifdef _AIX
180
#   define WAIT_STATUS_TYPE pid_t
181
#else
182
#ifndef NO_UNION_WAIT
183
#   define WAIT_STATUS_TYPE union wait
184
#else
185
#   define WAIT_STATUS_TYPE int
186
#endif
187
#endif
188
 
189
/*
190
 * Supply definitions for macros to query wait status, if not already
191
 * defined in header files above.
192
 */
193
 
194
#ifndef WIFEXITED
195
#   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
196
#endif
197
 
198
#ifndef WEXITSTATUS
199
#   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
200
#endif
201
 
202
#ifndef WIFSIGNALED
203
#   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
204
#endif
205
 
206
#ifndef WTERMSIG
207
#   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
208
#endif
209
 
210
#ifndef WIFSTOPPED
211
#   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
212
#endif
213
 
214
#ifndef WSTOPSIG
215
#   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
216
#endif
217
 
218
/*
219
 * Define constants for waitpid() system call if they aren't defined
220
 * by a system header file.
221
 */
222
 
223
#ifndef WNOHANG
224
#   define WNOHANG 1
225
#endif
226
#ifndef WUNTRACED
227
#   define WUNTRACED 2
228
#endif
229
 
230
/*
231
 * Supply macros for seek offsets, if they're not already provided by
232
 * an include file.
233
 */
234
 
235
#ifndef SEEK_SET
236
#   define SEEK_SET 0
237
#endif
238
 
239
#ifndef SEEK_CUR
240
#   define SEEK_CUR 1
241
#endif
242
 
243
#ifndef SEEK_END
244
#   define SEEK_END 2
245
#endif
246
 
247
/*
248
 * The stuff below is needed by the "time" command.  If this
249
 * system has no gettimeofday call, then must use times and the
250
 * CLK_TCK #define (from sys/param.h) to compute elapsed time.
251
 * Unfortunately, some systems only have HZ and no CLK_TCK, and
252
 * some might not even have HZ.
253
 */
254
 
255
#ifdef NO_GETTOD
256
#   include <sys/times.h>
257
#   include <sys/param.h>
258
#   ifndef CLK_TCK
259
#       ifdef HZ
260
#           define CLK_TCK HZ
261
#       else
262
#           define CLK_TCK 60
263
#       endif
264
#   endif
265
#else
266
#   ifdef HAVE_BSDGETTIMEOFDAY
267
#       define gettimeofday BSDgettimeofday
268
#   endif
269
#endif
270
 
271
#ifdef GETTOD_NOT_DECLARED
272
EXTERN int              gettimeofday _ANSI_ARGS_((struct timeval *tp,
273
                            struct timezone *tzp));
274
#endif
275
 
276
/*
277
 * Define access mode constants if they aren't already defined.
278
 */
279
 
280
#ifndef F_OK
281
#    define F_OK 00
282
#endif
283
#ifndef X_OK
284
#    define X_OK 01
285
#endif
286
#ifndef W_OK
287
#    define W_OK 02
288
#endif
289
#ifndef R_OK
290
#    define R_OK 04
291
#endif
292
 
293
/*
294
 * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
295
 * already defined.
296
 */
297
 
298
#ifndef FD_CLOEXEC
299
#   define FD_CLOEXEC 1
300
#endif
301
 
302
/*
303
 * On UNIX, there's no platform specific implementation of "TclpStat(...)"
304
 * or "TclpAccess(...)".  Simply call "stat(...)' and "access(...)"
305
 * respectively.
306
 */
307
 
308
#define TclpStat        stat
309
#define TclpAccess      access
310
 
311
/*
312
 * On systems without symbolic links (i.e. S_IFLNK isn't defined)
313
 * define "lstat" to use "stat" instead.
314
 */
315
 
316
#ifndef S_IFLNK
317
#   define lstat stat
318
#endif
319
 
320
/*
321
 * Define macros to query file type bits, if they're not already
322
 * defined.
323
 */
324
 
325
#ifndef S_ISREG
326
#   ifdef S_IFREG
327
#       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
328
#   else
329
#       define S_ISREG(m) 0
330
#   endif
331
# endif
332
#ifndef S_ISDIR
333
#   ifdef S_IFDIR
334
#       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
335
#   else
336
#       define S_ISDIR(m) 0
337
#   endif
338
# endif
339
#ifndef S_ISCHR
340
#   ifdef S_IFCHR
341
#       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
342
#   else
343
#       define S_ISCHR(m) 0
344
#   endif
345
# endif
346
#ifndef S_ISBLK
347
#   ifdef S_IFBLK
348
#       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
349
#   else
350
#       define S_ISBLK(m) 0
351
#   endif
352
# endif
353
#ifndef S_ISFIFO
354
#   ifdef S_IFIFO
355
#       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
356
#   else
357
#       define S_ISFIFO(m) 0
358
#   endif
359
# endif
360
#ifndef S_ISLNK
361
#   ifdef S_IFLNK
362
#       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
363
#   else
364
#       define S_ISLNK(m) 0
365
#   endif
366
# endif
367
#ifndef S_ISSOCK
368
#   ifdef S_IFSOCK
369
#       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
370
#   else
371
#       define S_ISSOCK(m) 0
372
#   endif
373
# endif
374
 
375
/*
376
 * Make sure that MAXPATHLEN is defined.
377
 */
378
 
379
#ifndef MAXPATHLEN
380
#   ifdef PATH_MAX
381
#       define MAXPATHLEN PATH_MAX
382
#   else
383
#       define MAXPATHLEN 2048
384
#   endif
385
#endif
386
 
387
/*
388
 * Make sure that L_tmpnam is defined.
389
 */
390
 
391
#ifndef L_tmpnam
392
#   define L_tmpnam 100
393
#endif
394
 
395
/*
396
 * The following macro defines the type of the mask arguments to
397
 * select:
398
 */
399
 
400
#ifndef NO_FD_SET
401
#   define SELECT_MASK fd_set
402
#else
403
#   ifndef _AIX
404
        typedef long fd_mask;
405
#   endif
406
#   if defined(_IBMR2)
407
#       define SELECT_MASK void
408
#   else
409
#       define SELECT_MASK int
410
#   endif
411
#endif
412
 
413
/*
414
 * Define "NBBY" (number of bits per byte) if it's not already defined.
415
 */
416
 
417
#ifndef NBBY
418
#   define NBBY 8
419
#endif
420
 
421
/*
422
 * The following macro defines the number of fd_masks in an fd_set:
423
 */
424
 
425
#ifndef FD_SETSIZE
426
#   ifdef OPEN_MAX
427
#       define FD_SETSIZE OPEN_MAX
428
#   else
429
#       define FD_SETSIZE 256
430
#   endif
431
#endif
432
#if !defined(howmany)
433
#   define howmany(x, y) (((x)+((y)-1))/(y))
434
#endif
435
#ifndef NFDBITS
436
#   define NFDBITS NBBY*sizeof(fd_mask)
437
#endif
438
#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
439
 
440
/*
441
 * The following implements the Unix method for exiting the process.
442
 */
443
#define TclPlatformExit(status) exit(status)
444
 
445
/*
446
 * The following functions always succeeds under Unix.
447
 */
448
 
449
#define TclHasSockets(interp) (TCL_OK)
450
 
451
/*
452
 * Variables provided by the C library:
453
 */
454
 
455
#if defined(_sgi) || defined(__sgi)
456
#define environ _environ
457
#endif
458
extern char **environ;
459
 
460
/*
461
 * At present (12/91) not all stdlib.h implementations declare strtod.
462
 * The declaration below is here to ensure that it's declared, so that
463
 * the compiler won't take the default approach of assuming it returns
464
 * an int.  There's no ANSI prototype for it because there would end
465
 * up being too many conflicts with slightly-different prototypes.
466
 */
467
 
468
extern double strtod();
469
 
470
/*
471
 * The following macros define time related functions in terms of
472
 * standard Unix routines.
473
 */
474
 
475
#define TclpGetDate(t,u) ((u) ? gmtime((t)) : localtime((t)))
476
#define TclStrftime(s,m,f,t) (strftime((s),(m),(f),(t)))
477
#define TclpGetPid(pid)     ((unsigned long) (pid))
478
 
479
#define TclpReleaseFile(file)   
480
 
481
/*
482
 * TclpFinalize is a noop on Unix systems.
483
 */
484
 
485
#define TclpFinalize()
486
 
487
/*
488
 * The following routine is only exported for testing purposes.
489
 */
490
 
491
EXTERN int      TclUnixWaitForFile _ANSI_ARGS_((int fd, int mask,
492
                    int timeout));
493
 
494
#endif /* _TCLUNIXPORT */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.