home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Shells / zsh-3.0.5-MIHS / src / Src / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-03  |  11.4 KB  |  479 lines

  1. /*
  2.  * $Id: system.h,v 2.7 1996/10/15 20:16:35 hzoli Exp $
  3.  *
  4.  * system.h - system configuration header file
  5.  *
  6.  * This file is part of zsh, the Z shell.
  7.  *
  8.  * Copyright (c) 1992-1996 Paul Falstad
  9.  * All rights reserved.
  10.  *
  11.  * Permission is hereby granted, without written agreement and without
  12.  * license or royalty fees, to use, copy, modify, and distribute this
  13.  * software and to distribute modified versions of this software for any
  14.  * purpose, provided that the above copyright notice and the following
  15.  * two paragraphs appear in all copies of this software.
  16.  *
  17.  * In no event shall Paul Falstad or the Zsh Development Group be liable
  18.  * to any party for direct, indirect, special, incidental, or consequential
  19.  * damages arising out of the use of this software and its documentation,
  20.  * even if Paul Falstad and the Zsh Development Group have been advised of
  21.  * the possibility of such damage.
  22.  *
  23.  * Paul Falstad and the Zsh Development Group specifically disclaim any
  24.  * warranties, including, but not limited to, the implied warranties of
  25.  * merchantability and fitness for a particular purpose.  The software
  26.  * provided hereunder is on an "as is" basis, and Paul Falstad and the
  27.  * Zsh Development Group have no obligation to provide maintenance,
  28.  * support, updates, enhancements, or modifications.
  29.  *
  30.  */
  31.  
  32. #ifdef __hpux
  33. #define _INCLUDE_POSIX_SOURCE
  34. #define _INCLUDE_XOPEN_SOURCE
  35. #define _INCLUDE_HPUX_SOURCE
  36. #endif
  37.  
  38. /* NeXT has half-implemented POSIX support *
  39.  * which currently fools configure         */
  40. #ifdef __NeXT__
  41. # undef HAVE_TERMIOS_H
  42. # undef HAVE_SYS_UTSNAME_H
  43. #endif
  44.  
  45. #ifdef PROTOTYPES
  46. # define _(Args) Args
  47. #else
  48. # define _(Args) ()
  49. #endif
  50.  
  51. #ifdef HAVE_LIBC_H     /* NeXT */
  52. # include <libc.h>
  53. #endif
  54.  
  55. #ifdef HAVE_UNISTD_H
  56. # include <sys/types.h>
  57. # include <unistd.h>
  58. #endif
  59.  
  60. #include <stdio.h>
  61. #include <pwd.h>
  62. #include <grp.h>
  63. #include <ctype.h>
  64. #include <sys/stat.h>
  65. #include <signal.h>
  66. #include <setjmp.h>
  67.  
  68. #if HAVE_DIRENT_H
  69. # include <dirent.h>
  70. # define NLENGTH(dirent) strlen((dirent)->d_name)
  71. #else
  72. # define dirent direct
  73. # define NLENGTH(dirent) (dirent)->d_namlen
  74. # if HAVE_SYS_NDIR_H
  75. #  include <sys/ndir.h>
  76. # endif
  77. # if HAVE_SYS_DIR_H
  78. #  include <sys/dir.h>
  79. # endif
  80. # if HAVE_NDIR_H
  81. #  include <ndir.h>
  82. # endif
  83. #endif
  84.  
  85. #ifdef HAVE_STDLIB_H
  86. # ifdef ZSH_MEM
  87.    /* malloc and calloc are macros in GNU's stdlib.h unless the
  88.     * the __MALLOC_0_RETURNS_NULL macro is defined */
  89. #  define __MALLOC_0_RETURNS_NULL
  90. # endif
  91. # include <stdlib.h>
  92. #endif
  93.  
  94. #ifdef HAVE_ERRNO_H
  95. # include <errno.h>
  96. #endif
  97.  
  98. #ifdef TIME_WITH_SYS_TIME
  99. # include <sys/time.h>
  100. # include <time.h>
  101. #else
  102. # ifdef HAVE_SYS_TIME_H
  103. # include <sys/time.h>
  104. # else
  105. #  include <time.h>
  106. # endif
  107. #endif
  108.  
  109. /* This is needed by some old SCO unices */
  110. #ifndef HAVE_STRUCT_TIMEZONE
  111. struct timezone {
  112.     int tz_minuteswest;
  113.     int tz_dsttime;
  114. };
  115. #endif
  116.  
  117. /* Sco needs the following include for struct utimbuf *
  118.  * which is strange considering we do not use that    *
  119.  * anywhere in the code                               */
  120. #ifdef __sco
  121. # include <utime.h>
  122. #endif
  123.  
  124. #ifdef HAVE_SYS_TIMES_H
  125. # include <sys/times.h>
  126. #endif
  127.  
  128. #if STDC_HEADERS || HAVE_STRING_H
  129. # include <string.h>
  130. /* An ANSI string.h and pre-ANSI memory.h might conflict.  */
  131. # if !STDC_HEADERS && HAVE_MEMORY_H
  132. #  include <memory.h>
  133. # endif /* not STDC_HEADERS and HAVE_MEMORY_H */
  134. #else   /* not STDC_HEADERS and not HAVE_STRING_H */
  135. # include <strings.h>
  136. /* memory.h and strings.h conflict on some systems.  */
  137. #endif /* not STDC_HEADERS and not HAVE_STRING_H */
  138.  
  139. #ifdef HAVE_LOCALE_H
  140. # include <locale.h>
  141. #endif
  142.  
  143. #ifdef HAVE_LIMITS_H
  144. # include <limits.h>
  145. #endif
  146.  
  147. /* we should be getting this value from pathconf(_PC_PATH_MAX) */
  148. /* but this is too much trouble                                */
  149. #ifndef PATH_MAX
  150. # ifdef MAXPATHLEN
  151. #  define PATH_MAX MAXPATHLEN
  152. # else
  153.    /* so we will just pick something */
  154. #  define PATH_MAX 1024
  155. # endif
  156. #endif
  157.  
  158. /* we should be getting this value from sysconf(_SC_OPEN_MAX) */
  159. /* but this is too much trouble                               */
  160. #ifndef OPEN_MAX
  161. # ifdef NOFILE
  162. #  define OPEN_MAX NOFILE
  163. # else
  164.    /* so we will just pick something */
  165. #  define OPEN_MAX 64
  166. # endif
  167. #endif
  168.  
  169. #ifdef HAVE_FCNTL_H
  170. # include <fcntl.h>
  171. #else
  172. # include <sys/file.h>
  173. #endif
  174.  
  175. /* The following will only be defined if <sys/wait.h> is POSIX.    *
  176.  * So we don't have to worry about union wait. But some machines   *
  177.  * (NeXT) include <sys/wait.h> from other include files, so we     *
  178.  * need to undef and then redefine the wait macros if <sys/wait.h> *
  179.  * is not POSIX.                                                   */
  180.  
  181. #ifdef HAVE_SYS_WAIT_H
  182. # include <sys/wait.h>
  183. #else
  184. #undef WIFEXITED
  185. #undef WEXITSTATUS
  186. #undef WIFSIGNALED
  187. #undef WTERMSIG
  188. #undef WCOREDUMP
  189. #undef WIFSTOPPED
  190. #undef WSTOPSIG
  191. #endif
  192.  
  193. /* missing macros for wait/waitpid/wait3 */
  194. #ifndef WIFEXITED
  195. # define WIFEXITED(X) (((X)&0377)==0)
  196. #endif
  197. #ifndef WEXITSTATUS
  198. # define WEXITSTATUS(X) (((X)>>8)&0377)
  199. #endif
  200. #ifndef WIFSIGNALED
  201. # define WIFSIGNALED(X) (((X)&0377)!=0&&((X)&0377)!=0177)
  202. #endif
  203. #ifndef WTERMSIG
  204. # define WTERMSIG(X) ((X)&0177)
  205. #endif
  206. #ifndef WCOREDUMP
  207. # define WCOREDUMP(X) ((X)&0200)
  208. #endif
  209. #ifndef WIFSTOPPED
  210. # define WIFSTOPPED(X) (((X)&0377)==0177)
  211. #endif
  212. #ifndef WSTOPSIG
  213. # define WSTOPSIG(X) (((X)>>8)&0377)
  214. #endif
  215.  
  216. #ifdef HAVE_SYS_SELECT_H
  217. # ifndef TIME_H_SELECT_H_CONFLICTS
  218. #  include <sys/select.h>
  219. # endif
  220. #endif
  221.  
  222. #ifdef HAVE_SYS_FILIO_H
  223. # include <sys/filio.h>
  224. #endif
  225.  
  226. #ifdef HAVE_TERMIOS_H
  227. # ifdef __sco
  228.    /* termios.h includes sys/termio.h instead of sys/termios.h; *
  229.     * hence the declaration for struct termios is missing       */
  230. #  include <sys/termios.h>
  231. # else
  232. #  include <termios.h>
  233. # endif
  234. # ifdef _POSIX_VDISABLE
  235. #  define VDISABLEVAL _POSIX_VDISABLE
  236. # else
  237. #  define VDISABLEVAL 0
  238. # endif
  239. # define HAS_TIO 1
  240. #else    /* not TERMIOS */
  241. # ifdef HAVE_TERMIO_H
  242. #  include <termio.h>
  243. #  define VDISABLEVAL -1
  244. #  define HAS_TIO 1
  245. # else   /* not TERMIOS and TERMIO */
  246. #  include <sgtty.h>
  247. # endif  /* HAVE_TERMIO_H  */
  248. #endif   /* HAVE_TERMIOS_H */
  249.  
  250. #ifdef HAVE_TERMCAP_H
  251. #include <termcap.h>
  252. #endif
  253.  
  254. #if defined(GWINSZ_IN_SYS_IOCTL) || defined(CLOBBERS_TYPEAHEAD)
  255. # include <sys/ioctl.h>
  256. #endif
  257. #ifdef WINSIZE_IN_PTEM
  258. # include <sys/stream.h>
  259. # include <sys/ptem.h>
  260. #endif
  261.  
  262. #ifdef HAVE_SYS_PARAM_H
  263. # include <sys/param.h>
  264. #endif
  265.  
  266. #ifdef HAVE_SYS_UTSNAME_H
  267. # include <sys/utsname.h>
  268. #endif
  269.  
  270. #ifdef HAVE_UTMPX_H
  271. # include <utmpx.h>
  272. # define STRUCT_UTMP struct utmpx
  273. # define ut_time ut_xtime
  274. #else
  275. # include <utmp.h>
  276. # define STRUCT_UTMP struct utmp
  277. #endif
  278.  
  279. #if !defined (UTMP_FILE) && defined (_PATH_UTMP)        /* 4.4BSD.  */
  280. # define UTMP_FILE _PATH_UTMP
  281. #endif
  282.  
  283. #if !defined (WTMP_FILE) && defined (_PATH_WTMP)
  284. # define WTMP_FILE _PATH_WTMP
  285. #endif
  286.  
  287. #ifdef UTMPX_FILE                                /* Solaris, SysVr4 */
  288. # undef  UTMP_FILE
  289. # define UTMP_FILE UTMPX_FILE
  290. #endif
  291.  
  292. #ifdef WTMPX_FILE                                /* Solaris. SysVr4 */
  293. # undef  WTMP_FILE
  294. # define WTMP_FILE WTMPX_FILE
  295. #endif
  296.  
  297. #ifndef UTMP_FILE                                /* use value found by configure */
  298. # define UTMP_FILE UTMP_FILE_CONFIG
  299. #endif
  300.  
  301. #ifndef WTMP_FILE                                /* use value found by configure */
  302. # define WTMP_FILE WTMP_FILE_CONFIG
  303. #endif
  304.  
  305. #ifdef HAVE_UT_HOST
  306. # define DEFAULT_WATCHFMT "%n has %a %l from %m."
  307. #else
  308. # define DEFAULT_WATCHFMT "%n has %a %l."
  309. #endif
  310.  
  311. #define DEFAULT_WORDCHARS "*?_-.[]~=/&;!#$%^(){}<>"
  312. #define DEFAULT_TIMEFMT   "%J  %U user %S system %P cpu %*E total"
  313.  
  314. /* Posix getpgrp takes no argument, while the BSD version *
  315.  * takes the process ID as an argument                    */
  316. #ifdef GETPGRP_VOID
  317. # define GETPGRP() getpgrp()
  318. #else
  319. # define GETPGRP() getpgrp(0)
  320. #endif
  321.  
  322. #ifndef HAVE_GETLOGIN
  323. # define getlogin() cuserid(NULL)
  324. #endif
  325.  
  326. #ifdef HAVE_SETPGID
  327. # define setpgrp setpgid
  328. #endif
  329.  
  330. /* can we set the user/group id of a process */
  331.  
  332. #ifndef HAVE_SETUID
  333. # ifdef HAVE_SETREUID
  334. #  define setuid(X) setreuid(X,X)
  335. #  define setgid(X) setregid(X,X)
  336. #  define HAVE_SETUID
  337. # endif
  338. #endif
  339.  
  340. /* can we set the effective user/group id of a process */
  341.  
  342. #ifndef HAVE_SETEUID
  343. # ifdef HAVE_SETREUID
  344. #  define seteuid(X) setreuid(-1,X)
  345. #  define setegid(X) setregid(-1,X)
  346. #  define HAVE_SETEUID
  347. # else
  348. #  ifdef HAVE_SETRESUID
  349. #   define seteuid(X) setresuid(-1,X,-1)
  350. #   define setegid(X) setresgid(-1,X,-1)
  351. #   define HAVE_SETEUID
  352. #  endif
  353. # endif
  354. #endif
  355.  
  356. #ifdef HAVE_SYS_RESOURCE_H
  357. # include <sys/resource.h>
  358. # if defined(__hpux) && !defined(RLIMIT_CPU)
  359. /* HPUX does have the BSD rlimits in the kernel.  Officially they are *
  360.  * unsupported but quite a few of them like RLIMIT_CORE seem to work. *
  361.  * All the following are in the <sys/resource.h> but made visible     *
  362.  * only for the kernel.                                               */
  363. #  define    RLIMIT_CPU    0
  364. #  define    RLIMIT_FSIZE    1
  365. #  define    RLIMIT_DATA    2
  366. #  define    RLIMIT_STACK    3
  367. #  define    RLIMIT_CORE    4
  368. #  define    RLIMIT_RSS    5
  369. #  define    RLIMIT_NOFILE   6
  370. #  define    RLIMIT_OPEN_MAX    RLIMIT_NOFILE
  371. #  define    RLIM_NLIMITS    7
  372. #  define    RLIM_INFINITY    0x7fffffff
  373. # endif
  374. #endif
  375.  
  376. /* we use the SVR4 constant instead of the BSD one */
  377. #if !defined(RLIMIT_NOFILE) && defined(RLIMIT_OFILE)
  378. # define RLIMIT_NOFILE RLIMIT_OFILE
  379. #endif
  380. #if !defined(RLIMIT_VMEM) && defined(RLIMIT_AS)
  381. # define RLIMIT_VMEM RLIMIT_AS
  382. #endif
  383.  
  384. /* DIGBUFSIZ is the length of a buffer which can hold the -LONG_MAX-1 *
  385.  * converted to printable decimal form including the sign and the     *
  386.  * terminating null character. Below 0.30103 > lg 2.                  */
  387. #define DIGBUFSIZE ((int) (((SIZEOF_LONG * 8) - 1) * 0.30103) + 3)
  388.  
  389. /* If your stat macros are broken, we will *
  390.  * just undefine them.                     */
  391. #ifdef  STAT_MACROS_BROKEN
  392. # ifdef S_ISBLK
  393. #  undef S_ISBLK
  394. # endif
  395. # ifdef S_ISCHR
  396. #  undef S_ISCHR
  397. # endif
  398. # ifdef S_ISDIR
  399. #  undef S_ISDIR
  400. # endif
  401. # ifdef S_ISFIFO
  402. #  undef S_ISFIFO
  403. # endif
  404. # ifdef S_ISLNK
  405. #  undef S_ISLNK
  406. # endif
  407. # ifdef S_ISMPB
  408. #  undef S_ISMPB
  409. # endif
  410. # ifdef S_ISMPC
  411. #  undef S_ISMPC
  412. # endif
  413. # ifdef S_ISNWK
  414. #  undef S_ISNWK
  415. # endif
  416. # ifdef S_ISREG
  417. #  undef S_ISREG
  418. # endif
  419. # ifdef S_ISSOCK
  420. #  undef S_ISSOCK
  421. # endif
  422. #endif  /* STAT_MACROS_BROKEN.  */
  423.  
  424. /* If you are missing the stat macros, we *
  425.  * define our own                         */
  426. #ifndef S_IFMT
  427. # define S_IFMT 0170000
  428. #endif
  429. #if !defined(S_ISBLK) && defined(S_IFBLK)
  430. # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  431. #endif
  432. #if !defined(S_ISCHR) && defined(S_IFCHR)
  433. # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  434. #endif
  435. #if !defined(S_ISDIR) && defined(S_IFDIR)
  436. # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  437. #endif
  438. #if !defined(S_ISREG) && defined(S_IFREG)
  439. # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  440. #endif
  441. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  442. # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  443. #endif
  444. #if !defined(S_ISLNK) && defined(S_IFLNK)
  445. # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  446. #endif
  447. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  448. # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  449. #endif
  450. #if !defined(S_ISMPB) && defined(S_IFMPB)        /*   V7  */
  451. # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  452. # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  453. #endif
  454. #if !defined(S_ISNWK) && defined(S_IFNWK)        /* HP/UX */
  455. # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  456. #endif
  457.  
  458. #ifndef HAVE_LSTAT
  459. # define lstat(X,Y) stat(X,Y)
  460. #endif
  461.  
  462. #ifndef F_OK          /* missing macros for access() */
  463. # define F_OK 0
  464. # define X_OK 1
  465. # define W_OK 2
  466. # define R_OK 4
  467. #endif
  468.  
  469. extern char **environ;     /* environment variable list */
  470.  
  471. /* These variables are sometimes defined in, *
  472.  * and needed by, the termcap library.       */
  473.  
  474. #if MUST_DEFINE_OSPEED
  475. extern char PC, *BC, *UP;
  476. extern short ospeed;
  477. #endif
  478.  
  479.