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