home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / tclunix.h < prev    next >
C/C++ Source or Header  |  1995-03-23  |  7KB  |  308 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. #ifdef __OS2__
  38. #include <io.h>
  39. #include <process.h>
  40. #include <direct.h>
  41. #endif
  42.  
  43. #ifndef _TCLUNIX
  44. #define _TCLUNIX
  45.  
  46. #include <errno.h>
  47. #include <fcntl.h>
  48. #ifndef __OS2__
  49. #include <pwd.h>
  50. #endif
  51. #include <signal.h>
  52. #ifndef __OS2__
  53. #include <sys/param.h>
  54. #endif
  55. #include <sys/types.h>
  56. #ifdef __OS2__
  57. #include "os2/dirent.h"
  58. #else
  59. #ifdef USE_DIRENT2_H
  60. #   include "compat/dirent2.h"
  61. #else
  62. #   ifdef NO_DIRENT_H
  63. #    include "compat/dirent.h"
  64. #   else
  65. #    include <dirent.h>
  66. #   endif
  67. #endif
  68. #endif
  69. #ifndef __OS2__
  70. #include <sys/file.h>
  71. #endif
  72. #include <sys/stat.h>
  73. #ifndef NO_SYS_TIME_H
  74. #   include <sys/time.h>
  75. #else
  76. #   include <time.h>
  77. #endif
  78. #ifndef NO_SYS_WAIT_H
  79. #   include <sys/wait.h>
  80. #endif
  81.  
  82. #ifndef __OS2__
  83. #ifdef HAVE_UNISTD_H
  84. #   include <unistd.h>
  85. #else
  86. #   include "compat/unistd.h"
  87. #endif
  88. #endif
  89. /*
  90.  * Not all systems declare the errno variable in errno.h. so this
  91.  * file does it explicitly.  The list of system error messages also
  92.  * isn't generally declared in a header file anywhere.
  93.  */
  94.  
  95. extern int errno;
  96.  
  97. /*
  98.  * The type of the status returned by wait varies from UNIX system
  99.  * to UNIX system.  The macro below defines it:
  100.  */
  101.  
  102. #ifdef AIX
  103. #   define WAIT_STATUS_TYPE pid_t
  104. #else
  105. #ifndef NO_UNION_WAIT
  106. #   define WAIT_STATUS_TYPE union wait
  107. #else
  108. #   define WAIT_STATUS_TYPE int
  109. #endif
  110. #endif
  111.  
  112. /*
  113.  * Supply definitions for macros to query wait status, if not already
  114.  * defined in header files above.
  115.  */
  116.  
  117. #ifndef WIFEXITED
  118. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  119. #endif
  120.  
  121. #ifndef WEXITSTATUS
  122. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  123. #endif
  124.  
  125. #ifndef WIFSIGNALED
  126. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  127. #endif
  128.  
  129. #ifndef WTERMSIG
  130. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  131. #endif
  132.  
  133. #ifndef WIFSTOPPED
  134. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  135. #endif
  136.  
  137. #ifndef WSTOPSIG
  138. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  139. #endif
  140.  
  141. /*
  142.  * Supply macros for seek offsets, if they're not already provided by
  143.  * an include file.
  144.  */
  145.  
  146. #ifndef SEEK_SET
  147. #   define SEEK_SET 0
  148. #endif
  149.  
  150. #ifndef SEEK_CUR
  151. #   define SEEK_CUR 1
  152. #endif
  153.  
  154. #ifndef SEEK_END
  155. #   define SEEK_END 2
  156. #endif
  157.  
  158. /*
  159.  * The stuff below is needed by the "time" command.  If this
  160.  * system has no gettimeofday call, then must use times and the
  161.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  162.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  163.  * some might not even have HZ.
  164.  */
  165.  
  166. #ifdef NO_GETTOD
  167. #   include <sys/times.h>
  168. #   include <sys/param.h>
  169. #   ifndef CLK_TCK
  170. #       ifdef HZ
  171. #           define CLK_TCK HZ
  172. #       else
  173. #           define CLK_TCK 60
  174. #       endif
  175. #   endif
  176. #endif
  177.  
  178. /*
  179.  * Define access mode constants if they aren't already defined.
  180.  */
  181.  
  182. #ifndef F_OK
  183. #    define F_OK 00
  184. #endif
  185. #ifndef X_OK
  186. #    define X_OK 01
  187. #endif
  188. #ifndef W_OK
  189. #    define W_OK 02
  190. #endif
  191. #ifndef R_OK
  192. #    define R_OK 04
  193. #endif
  194.  
  195. /*
  196.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  197.  * define "lstat" to use "stat" instead.
  198.  */
  199.  
  200. #ifndef S_IFLNK
  201. #   define lstat stat
  202. #endif
  203.  
  204. /*
  205.  * Define macros to query file type bits, if they're not already
  206.  * defined.
  207.  */
  208.  
  209. #ifdef __OS2__
  210. #define S_IFMT 0170000
  211. #endif
  212.  
  213. #ifndef S_ISREG
  214. #   ifdef S_IFREG
  215. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  216. #   else
  217. #       define S_ISREG(m) 0
  218. #   endif
  219. # endif
  220. #ifndef S_ISDIR
  221. #   ifdef S_IFDIR
  222. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  223. #   else
  224. #       define S_ISDIR(m) 0
  225. #   endif
  226. # endif
  227. #ifndef S_ISCHR
  228. #   ifdef S_IFCHR
  229. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  230. #   else
  231. #       define S_ISCHR(m) 0
  232. #   endif
  233. # endif
  234. #ifndef S_ISBLK
  235. #   ifdef S_IFBLK
  236. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  237. #   else
  238. #       define S_ISBLK(m) 0
  239. #   endif
  240. # endif
  241. #ifndef S_ISFIFO
  242. #   ifdef S_IFIFO
  243. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  244. #   else
  245. #       define S_ISFIFO(m) 0
  246. #   endif
  247. # endif
  248. #ifndef S_ISLNK
  249. #   ifdef S_IFLNK
  250. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  251. #   else
  252. #       define S_ISLNK(m) 0
  253. #   endif
  254. # endif
  255. #ifndef S_ISSOCK
  256. #   ifdef S_IFSOCK
  257. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  258. #   else
  259. #       define S_ISSOCK(m) 0
  260. #   endif
  261. # endif
  262.  
  263. /*
  264.  * Make sure that MAXPATHLEN is defined.
  265.  */
  266.  
  267. #ifndef MAXPATHLEN
  268. #   ifdef PATH_MAX
  269. #       define MAXPATHLEN PATH_MAX
  270. #   else
  271. #       define MAXPATHLEN 2048
  272. #   endif
  273. #endif
  274.  
  275. /*
  276.  * Make sure that L_tmpnam is defined.
  277.  */
  278.  
  279. #ifndef L_tmpnam
  280. #   define L_tmpnam 100
  281. #endif
  282.  
  283. /*
  284.  * Substitute Tcl's own versions for several system calls.  The
  285.  * Tcl versions retry automatically if interrupted by signals.
  286.  * (see tclUnixUtil.c).
  287.  */
  288.  
  289. #define open(a,b,c) TclOpen(a,b,c)
  290. #define read(a,b,c) TclRead(a,b,c)
  291. #define waitpid(a,b,c) TclWaitpid(a,b,c)
  292. #define write(a,b,c) TclWrite(a,b,c)
  293. EXTERN int    TclOpen _ANSI_ARGS_((char *path, int oflag, int mode));
  294. EXTERN int    TclRead _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  295. EXTERN int    TclWaitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  296. EXTERN int    TclWrite _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  297.  
  298. /*
  299.  * Variables provided by the C library:
  300.  */
  301.  
  302. #if defined(_sgi) || defined(__sgi)
  303. #define environ _environ
  304. #endif
  305. extern char **environ;
  306.  
  307. #endif /* _TCLUNIX */
  308.