home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / tcl / tcl+tk+t / tcl7.3l1 / tcl7 / tcl7.3 / tclUnix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-28  |  6.6 KB  |  286 lines

  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.  *    Much of the material in this file was originally contributed
  12.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  13.  *
  14.  * Copyright (c) 1991-1993 The Regents of the University of California.
  15.  * All rights reserved.
  16.  *
  17.  * Permission is hereby granted, without written agreement and without
  18.  * license or royalty fees, to use, copy, modify, and distribute this
  19.  * software and its documentation for any purpose, provided that the
  20.  * above copyright notice and the following two paragraphs appear in
  21.  * all copies of this software.
  22.  * 
  23.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  24.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  25.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  26.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  29.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  30.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  31.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  32.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  33.  *
  34.  * $Header: /user6/ouster/tcl/RCS/tclUnix.h,v 1.46 93/10/28 16:32:28 ouster Exp $ SPRITE (Berkeley)
  35.  */
  36.  
  37. #ifndef _TCLUNIX
  38. #define _TCLUNIX
  39.  
  40. #include <errno.h>
  41. #include <fcntl.h>
  42. #include <pwd.h>
  43. #include <signal.h>
  44. #include <sys/param.h>
  45. #include <sys/types.h>
  46. #ifdef USE_DIRENT2_H
  47. #   include "compat/dirent2.h"
  48. #else
  49. #   ifdef NO_DIRENT_H
  50. #    include "compat/dirent.h"
  51. #   else
  52. #    include <dirent.h>
  53. #   endif
  54. #endif
  55. #include <sys/file.h>
  56. #include <sys/stat.h>
  57. #ifndef NO_SYS_TIME_H
  58. #   include <sys/time.h>
  59. #else
  60. #   include <time.h>
  61. #endif
  62. #ifndef NO_SYS_WAIT_H
  63. #   include <sys/wait.h>
  64. #endif
  65. #ifdef HAVE_UNISTD_H
  66. #   include <unistd.h>
  67. #else
  68. #   include "compat/unistd.h"
  69. #endif
  70.  
  71. /*
  72.  * Not all systems declare the errno variable in errno.h. so this
  73.  * file does it explicitly.  The list of system error messages also
  74.  * isn't generally declared in a header file anywhere.
  75.  */
  76.  
  77. extern int errno;
  78.  
  79. /*
  80.  * The type of the status returned by wait varies from UNIX system
  81.  * to UNIX system.  The macro below defines it:
  82.  */
  83.  
  84. #ifdef AIX
  85. #   define WAIT_STATUS_TYPE pid_t
  86. #else
  87. #ifndef NO_UNION_WAIT
  88. #   define WAIT_STATUS_TYPE union wait
  89. #else
  90. #   define WAIT_STATUS_TYPE int
  91. #endif
  92. #endif
  93.  
  94. /*
  95.  * Supply definitions for macros to query wait status, if not already
  96.  * defined in header files above.
  97.  */
  98.  
  99. #ifndef WIFEXITED
  100. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  101. #endif
  102.  
  103. #ifndef WEXITSTATUS
  104. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  105. #endif
  106.  
  107. #ifndef WIFSIGNALED
  108. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  109. #endif
  110.  
  111. #ifndef WTERMSIG
  112. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  113. #endif
  114.  
  115. #ifndef WIFSTOPPED
  116. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  117. #endif
  118.  
  119. #ifndef WSTOPSIG
  120. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  121. #endif
  122.  
  123. /*
  124.  * Supply macros for seek offsets, if they're not already provided by
  125.  * an include file.
  126.  */
  127.  
  128. #ifndef SEEK_SET
  129. #   define SEEK_SET 0
  130. #endif
  131.  
  132. #ifndef SEEK_CUR
  133. #   define SEEK_CUR 1
  134. #endif
  135.  
  136. #ifndef SEEK_END
  137. #   define SEEK_END 2
  138. #endif
  139.  
  140. /*
  141.  * The stuff below is needed by the "time" command.  If this
  142.  * system has no gettimeofday call, then must use times and the
  143.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  144.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  145.  * some might not even have HZ.
  146.  */
  147.  
  148. #ifdef NO_GETTOD
  149. #   include <sys/times.h>
  150. #   include <sys/param.h>
  151. #   ifndef CLK_TCK
  152. #       ifdef HZ
  153. #           define CLK_TCK HZ
  154. #       else
  155. #           define CLK_TCK 60
  156. #       endif
  157. #   endif
  158. #endif
  159.  
  160. /*
  161.  * Define access mode constants if they aren't already defined.
  162.  */
  163.  
  164. #ifndef F_OK
  165. #    define F_OK 00
  166. #endif
  167. #ifndef X_OK
  168. #    define X_OK 01
  169. #endif
  170. #ifndef W_OK
  171. #    define W_OK 02
  172. #endif
  173. #ifndef R_OK
  174. #    define R_OK 04
  175. #endif
  176.  
  177. /*
  178.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  179.  * define "lstat" to use "stat" instead.
  180.  */
  181.  
  182. #ifndef S_IFLNK
  183. #   define lstat stat
  184. #endif
  185.  
  186. /*
  187.  * Define macros to query file type bits, if they're not already
  188.  * defined.
  189.  */
  190.  
  191. #ifndef S_ISREG
  192. #   ifdef S_IFREG
  193. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  194. #   else
  195. #       define S_ISREG(m) 0
  196. #   endif
  197. # endif
  198. #ifndef S_ISDIR
  199. #   ifdef S_IFDIR
  200. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  201. #   else
  202. #       define S_ISDIR(m) 0
  203. #   endif
  204. # endif
  205. #ifndef S_ISCHR
  206. #   ifdef S_IFCHR
  207. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  208. #   else
  209. #       define S_ISCHR(m) 0
  210. #   endif
  211. # endif
  212. #ifndef S_ISBLK
  213. #   ifdef S_IFBLK
  214. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  215. #   else
  216. #       define S_ISBLK(m) 0
  217. #   endif
  218. # endif
  219. #ifndef S_ISFIFO
  220. #   ifdef S_IFIFO
  221. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  222. #   else
  223. #       define S_ISFIFO(m) 0
  224. #   endif
  225. # endif
  226. #ifndef S_ISLNK
  227. #   ifdef S_IFLNK
  228. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  229. #   else
  230. #       define S_ISLNK(m) 0
  231. #   endif
  232. # endif
  233. #ifndef S_ISSOCK
  234. #   ifdef S_IFSOCK
  235. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  236. #   else
  237. #       define S_ISSOCK(m) 0
  238. #   endif
  239. # endif
  240.  
  241. /*
  242.  * Make sure that MAXPATHLEN is defined.
  243.  */
  244.  
  245. #ifndef MAXPATHLEN
  246. #   ifdef PATH_MAX
  247. #       define MAXPATHLEN PATH_MAX
  248. #   else
  249. #       define MAXPATHLEN 2048
  250. #   endif
  251. #endif
  252.  
  253. /*
  254.  * Make sure that L_tmpnam is defined.
  255.  */
  256.  
  257. #ifndef L_tmpnam
  258. #   define L_tmpnam 100
  259. #endif
  260.  
  261. /*
  262.  * Substitute Tcl's own versions for several system calls.  The
  263.  * Tcl versions retry automatically if interrupted by signals.
  264.  * (see tclUnixUtil.c).
  265.  */
  266.  
  267. #define open(a,b,c) TclOpen(a,b,c)
  268. #define read(a,b,c) TclRead(a,b,c)
  269. #define waitpid(a,b,c) TclWaitpid(a,b,c)
  270. #define write(a,b,c) TclWrite(a,b,c)
  271. EXTERN int    TclOpen _ANSI_ARGS_((char *path, int oflag, int mode));
  272. EXTERN int    TclRead _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  273. EXTERN int    TclWaitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  274. EXTERN int    TclWrite _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  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. #endif /* _TCLUNIX */
  286.