OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / tinytcl / tclUnix.h
1 /*
2  * tclUnix.h --
3  *
4  *      This file reads in UNIX-related header files and sets up
5  *      UNIX-related macros for Tcl's UNIX core.  It should be the
6  *      only file that contains #ifdefs to handle different flavors
7  *      of UNIX.  This file sets up the union of all UNIX-related
8  *      things needed by any of the Tcl core files.  This file
9  *      depends on configuration #defines in tclConfig.h
10  *
11  *      The material in this file was originally contributed by
12  *      Karl Lehenbauer, Mark Diekhans and Peter da Silva.
13  *
14  * Copyright 1991 Regents of the University of California
15  * Permission to use, copy, modify, and distribute this
16  * software and its documentation for any purpose and without
17  * fee is hereby granted, provided that this copyright
18  * notice appears in all copies.  The University of California
19  * makes no representations about the suitability of this
20  * software for any purpose.  It is provided "as is" without
21  * express or implied warranty.
22  *
23  * $Id: tclUnix.h,v 1.1.1.1 2001/04/29 20:35:04 karll Exp $
24  */
25
26 #ifndef _TCLUNIX
27 #define _TCLUNIX
28
29 /*
30  * The following #defines are used to distinguish between different
31  * UNIX systems.  These #defines are normally set by the "config" script
32  * based on information it gets by looking in the include and library
33  * areas.  The defaults below are for BSD-based systems like SunOS
34  * or Ultrix.
35  *
36  * TCL_GETTOD -                 1 means there exists a library procedure
37  *                              "gettimeofday" (e.g. BSD systems).  0 means
38  *                              have to use "times" instead.
39  * TCL_GETWD -                  1 means there exists a library procedure
40  *                              "getwd" (e.g. BSD systems).  0 means
41  *                              have to use "getcwd" instead.
42  * TCL_SYS_ERRLIST -            1 means that the array sys_errlist is
43  *                              defined as part of the C library.
44  * TCL_SYS_TIME_H -             1 means there exists an include file
45  *                              <sys/time.h> (e.g. BSD derivatives).
46  * TCL_SYS_WAIT_H -             1 means there exists an include file
47  *                              <sys/wait.h> that defines constants related
48  *                              to the results of "wait".
49  * TCL_UNION_WAIT -             1 means that the "wait" system call returns
50  *                              a structure of type "union wait" (e.g. BSD
51  *                              systems).  0 means "wait" returns an int
52  *                              (e.g. System V and POSIX).
53  * TCL_PID_T -                  1 means that <sys/types> defines the type
54  *                              pid_t.  0 means that it doesn't.
55  * TCL_UID_T -                  1 means that <sys/types> defines the type
56  *                              uid_t.  0 means that it doesn't.
57  */
58
59 #define TCL_GETTOD 1
60 #define TCL_SYS_ERRLIST 1
61 #define TCL_SYS_TIME_H 1
62 #define TCL_SYS_WAIT_H 1
63 #define TCL_UNION_WAIT 0
64 #define TCL_PID_T 1
65 #define TCL_UID_T 1
66
67 #define HAVE_MKSTEMP
68 #define HAVE_GETHOSTNAME
69
70 #include <errno.h>
71 #include <fcntl.h>
72 #include <limits.h>
73 #include <pwd.h>
74 #include <unistd.h>
75            #if 0
76        #include <pwd.h>
77        #include <sys/types.h>
78            #endif
79
80 #include <signal.h>
81 /* #include <sys/param.h> */
82 #include <sys/types.h>
83 #include <dirent.h>
84 /* #include <sys/file.h> */
85 #include <sys/stat.h>
86 #include <sys/stat.h>
87 #if TCL_SYS_TIME_H
88  #   include <sys/time.h> 
89 #else
90 #   include <time.h>
91 #endif
92 #if TCL_SYS_WAIT_H
93  #   include <sys/wait.h> 
94 #endif
95
96 /*
97  * Not all systems declare the errno variable in errno.h. so this
98  * file does it explicitly.  The list of system error messages also
99  * isn't generally declared in a header file anywhere.
100  */
101
102 extern int errno;
103 extern int sys_nerr;
104 /* extern char *sys_errlist[]; */
105
106 /*
107  * The type of the status returned by wait varies from UNIX system
108  * to UNIX system.  The macro below defines it:
109  */
110
111 #if TCL_UNION_WAIT
112 #   define WAIT_STATUS_TYPE union wait
113 #else
114 #   define WAIT_STATUS_TYPE int
115 #endif
116
117 /*
118  * Supply definitions for macros to query wait status, if not already
119  * defined in header files above.
120  */
121
122 #ifndef WIFEXITED
123 #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
124 #endif
125
126 #ifndef WEXITSTATUS
127 #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
128 #endif
129
130 #ifndef WIFSIGNALED
131 #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
132 #endif
133
134 #ifndef WTERMSIG
135 #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
136 #endif
137
138 #ifndef WIFSTOPPED
139 #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
140 #endif
141
142 #ifndef WSTOPSIG
143 #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
144 #endif
145
146 /*
147  * Supply macros for seek offsets, if they're not already provided by
148  * an include file.
149  */
150
151 #ifndef SEEK_SET
152 #   define SEEK_SET 0
153 #endif
154
155 #ifndef SEEK_CUR
156 #   define SEEK_CUR 1
157 #endif
158
159 #ifndef SEEK_END
160 #   define SEEK_END 2
161 #endif
162
163 /*
164  * The stuff below is needed by the "time" command.  If this
165  * system has no gettimeofday call, then must use times and the
166  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
167  * Unfortunately, some systems only have HZ and no CLK_TCK, and
168  * some might not even have HZ.
169  */
170
171 #if ! TCL_GETTOD
172 #   include <sys/times.h>
173 #   include <sys/param.h>
174 #   ifndef CLK_TCK
175 #       ifdef HZ
176 #           define CLK_TCK HZ
177 #       else
178 #           define CLK_TCK 60
179 #       endif
180 #   endif
181 #endif
182
183 /*
184  * Define access mode constants if they aren't already defined.
185  */
186
187 #ifndef F_OK
188 #    define F_OK 00
189 #endif
190 #ifndef X_OK
191 #    define X_OK 01
192 #endif
193 #ifndef W_OK
194 #    define W_OK 02
195 #endif
196 #ifndef R_OK
197 #    define R_OK 04
198 #endif
199
200 /*
201  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
202  * define "lstat" to use "stat" instead.
203  */
204
205 #ifndef S_IFLNK
206 #   define lstat stat
207 #endif
208
209 /*
210  * Define macros to query file type bits, if they're not already
211  * defined.
212  */
213
214 #ifndef S_ISREG
215 #   ifdef S_IFREG
216 #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
217 #   else
218 #       define S_ISREG(m) 0
219 #   endif
220 # endif
221 #ifndef S_ISDIR
222 #   ifdef S_IFDIR
223 #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
224 #   else
225 #       define S_ISDIR(m) 0
226 #   endif
227 # endif
228 #ifndef S_ISCHR
229 #   ifdef S_IFCHR
230 #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
231 #   else
232 #       define S_ISCHR(m) 0
233 #   endif
234 # endif
235 #ifndef S_ISBLK
236 #   ifdef S_IFBLK
237 #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
238 #   else
239 #       define S_ISBLK(m) 0
240 #   endif
241 # endif
242 #ifndef S_ISFIFO
243 #   ifdef S_IFIFO
244 #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
245 #   else
246 #       define S_ISFIFO(m) 0
247 #   endif
248 # endif
249 #ifndef S_ISLNK
250 #   ifdef S_IFLNK
251 #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
252 #   else
253 #       define S_ISLNK(m) 0
254 #   endif
255 # endif
256 #ifndef S_ISSOCK
257 #   ifdef S_IFSOCK
258 #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
259 #   else
260 #       define S_ISSOCK(m) 0
261 #   endif
262 # endif
263
264 /*
265  * Make sure that MAXPATHLEN is defined.
266  */
267
268 #ifndef MAXPATHLEN
269 #   ifdef PATH_MAX
270 #       define MAXPATHLEN PATH_MAX
271 #   else
272 #       define MAXPATHLEN 2048
273 #   endif
274 #endif
275
276 /*
277  * Define pid_t and uid_t if they're not already defined.
278  */
279
280 #if ! TCL_PID_T
281 #   define pid_t int
282 #endif
283 #if ! TCL_UID_T
284 #   define uid_t int
285 #endif
286
287 /*
288  * Variables provided by the C library:
289  */
290
291 #if defined(_sgi) || defined(__sgi)
292 #define environ _environ
293 #endif
294 extern char **environ;
295
296 /* uClinux can't do fork(), only vfork() */
297 #ifdef __uClinux__
298 #define NO_FORK
299 #endif
300
301 /*
302  * Library procedures used by Tcl but not declared in a header file:
303  */
304
305 #ifndef _CRAY
306 extern int      access     _ANSI_ARGS_((CONST char *path, int mode));
307 extern int      chdir      _ANSI_ARGS_((CONST char *path));
308 extern int      close      _ANSI_ARGS_((int fd));
309 extern int      dup2       _ANSI_ARGS_((int src, int dst));
310 extern void     endpwent   _ANSI_ARGS_((void));
311 /* extern int   execvp     _ANSI_ARGS_((CONST char *name, char **argv)); */
312 extern void     _exit      _ANSI_ARGS_((int status));
313 /* extern pid_t fork       _ANSI_ARGS_((void)); */
314 /* extern uid_t geteuid    _ANSI_ARGS_((void)); */
315 /* extern pid_t getpid     _ANSI_ARGS_((void)); */
316 /* extern char *        getcwd     _ANSI_ARGS_((char *buffer, int size)); */
317 extern char *   getwd      _ANSI_ARGS_((char *buffer));
318 /* extern int   kill       _ANSI_ARGS_((pid_t pid, int sig)); */
319 /* extern long  lseek      _ANSI_ARGS_((int fd, int offset, int whence)); */
320 extern char *   mktemp     _ANSI_ARGS_((char *template));
321 #if !(defined(sparc) || defined(_IBMR2))
322 extern int      open       _ANSI_ARGS_((CONST char *path, int flags, ...));
323 #endif
324 extern int      pipe       _ANSI_ARGS_((int *fdPtr));
325 /* extern int   read       _ANSI_ARGS_((int fd, char *buf, int numBytes)); */
326 /*extern int    readlink   _ANSI_ARGS_((CONST char *path, char *buf, int size));*/
327 extern int      unlink     _ANSI_ARGS_((CONST char *path));
328 /* extern int   write      _ANSI_ARGS_((int fd, char *buf, int numBytes)); */
329 #endif /* _CRAY */
330
331 #endif /* _TCLUNIX */