Source:NetHack 3.4.3/include/system.h

From NetHackWiki
Jump to: navigation, search

Below is the full text to include/system.h from NetHack 3.4.3. To link to a particular line, write [[system.h#line123]], for example.

  1. /*	SCCS Id: @(#)system.h	3.4	2001/12/07	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #ifndef SYSTEM_H
  2. #define SYSTEM_H
  3.  
  4. #if !defined(__cplusplus) && !defined(__GO32__)
  5.  
  6. #define E extern
  7.  
  8. /* some old <sys/types.h> may not define off_t and size_t; if your system is
  9. * one of these, define them by hand below
  10. */
  11. #if (defined(VMS) && !defined(__GNUC__)) || defined(MAC)
  12. #include <types.h>
  13. #else
  14. # ifndef AMIGA
  15. #include <sys/types.h>
  16. # endif
  17. #endif
  18.  
  19. #if (defined(MICRO) && !defined(TOS)) || defined(ANCIENT_VAXC)
  20. # if !defined(_SIZE_T) && !defined(__size_t) /* __size_t for CSet/2 */
  21. #  define _SIZE_T
  22. #  if !((defined(MSDOS) || defined(OS2)) && defined(_SIZE_T_DEFINED)) /* MSC 5.1 */
  23. #   if !(defined(__GNUC__) && defined(AMIGA))
  24. typedef unsigned int	size_t;
  25. #   endif
  26. #  endif
  27. # endif
  28. #endif	/* MICRO && !TOS */
  29.  
  30. #if defined(__TURBOC__) || defined(MAC)
  31. #include <time.h>	/* time_t is not in <sys/types.h> */
  32. #endif
  33. #if defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))
  34. /* The Ultrix v3.0 <sys/types.h> seems to be very wrong. */
  35. # define time_t long
  36. #endif
  37.  
  38. #if defined(ULTRIX) || defined(VMS)
  39. # define off_t long
  40. #endif
  41. #if defined(AZTEC) || defined(THINKC4) || defined(__TURBOC__)
  42. typedef long	off_t;
  43. #endif
  44.  
  45. #endif /* !__cplusplus && !__GO32__ */
  46.  
  47. /* You may want to change this to fit your system, as this is almost
  48. * impossible to get right automatically.
  49. * This is the type of signal handling functions.
  50. */
  51. #if !defined(OS2) && (defined(_MSC_VER) || defined(__TURBOC__) || defined(__SC__) || defined(WIN32))
  52. # define SIG_RET_TYPE void (__cdecl *)(int)
  53. #endif
  54. #ifndef SIG_RET_TYPE
  55. # if defined(NHSTDC) || defined(POSIX_TYPES) || defined(OS2) || defined(__DECC)
  56. #  define SIG_RET_TYPE void (*)()
  57. # endif
  58. #endif
  59. #ifndef SIG_RET_TYPE
  60. # if defined(ULTRIX) || defined(SUNOS4) || defined(SVR3) || defined(SVR4)
  61. 	/* SVR3 is defined automatically by some systems */
  62. #  define SIG_RET_TYPE void (*)()
  63. # endif
  64. #endif
  65. #ifndef SIG_RET_TYPE	/* BSD, SIII, SVR2 and earlier, Sun3.5 and earlier */
  66. # define SIG_RET_TYPE int (*)()
  67. #endif
  68.  
  69. #if !defined(__cplusplus) && !defined(__GO32__)
  70.  
  71. #if defined(BSD) || defined(ULTRIX) || defined(RANDOM)
  72. # ifdef random
  73. # undef random
  74. # endif
  75. # if !defined(__SC__) && !defined(LINUX)
  76. E  long NDECL(random);
  77. # endif
  78. # if (!defined(SUNOS4) && !defined(bsdi) && !defined(__FreeBSD__)) || defined(RANDOM)
  79. E void FDECL(srandom, (unsigned int));
  80. # else
  81. #  if !defined(bsdi) && !defined(__FreeBSD__)
  82. E int FDECL(srandom, (unsigned int));
  83. #  endif
  84. # endif
  85. #else
  86. E long lrand48();
  87. E void srand48();
  88. #endif /* BSD || ULTRIX || RANDOM */
  89.  
  90. #if !defined(BSD) || defined(ultrix)
  91. 			/* real BSD wants all these to return int */
  92. # ifndef MICRO
  93. E void FDECL(exit, (int));
  94. # endif /* MICRO */
  95. /* compensate for some CSet/2 bogosities */
  96. # if defined(OS2_CSET2) && defined(OS2_CSET2_VER_2)
  97. #  define open	  _open
  98. #  define close   _close
  99. #  define read	  _read
  100. #  define write   _write
  101. #  define lseek   _lseek
  102. #  define chdir   _chdir
  103. #  define getcwd  _getcwd
  104. #  define setmode _setmode
  105. # endif /* OS2_CSET2 && OS2_CSET2_VER_2 */
  106. /* If flex thinks that we're not __STDC__ it declares free() to return
  107. int and we die.  We must use __STDC__ instead of NHSTDC because
  108. the former is naturally what flex tests for. */
  109. # if defined(__STDC__) || !defined(FLEX_SCANNER)
  110. #  ifndef OS2_CSET2
  111. #   ifndef MONITOR_HEAP
  112. E void FDECL(free, (genericptr_t));
  113. #   endif
  114. #  endif
  115. # endif
  116. #if !defined(__SASC_60) && !defined(_DCC) && !defined(__SC__)
  117. # if defined(AMIGA) && !defined(AZTEC_50) && !defined(__GNUC__)
  118. E int FDECL(perror, (const char *));
  119. # else
  120. #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
  121. E void FDECL(perror, (const char *));
  122. #  endif
  123. # endif
  124. #endif
  125. #endif
  126. #ifndef NeXT
  127. #ifdef POSIX_TYPES
  128. E void FDECL(qsort, (genericptr_t,size_t,size_t,
  129. 		     int(*)(const genericptr,const genericptr)));
  130. #else
  131. # if defined(BSD) || defined(ULTRIX)
  132. E  int qsort();
  133. # else
  134. #  if !defined(LATTICE) && !defined(AZTEC_50)
  135. E   void FDECL(qsort, (genericptr_t,size_t,size_t,
  136. 		       int(*)(const genericptr,const genericptr)));
  137. #  endif
  138. # endif
  139. #endif
  140. #endif /* NeXT */
  141.  
  142. #ifndef __SASC_60
  143. #if !defined(AZTEC_50) && !defined(__GNUC__)
  144. /* may already be defined */
  145.  
  146. # ifdef ULTRIX
  147. #  ifdef ULTRIX_PROTO
  148. E int FDECL(lseek, (int,off_t,int));
  149. #  else
  150. E long FDECL(lseek, (int,off_t,int));
  151. #  endif
  152. /* Ultrix 3.0 man page mistakenly says it returns an int. */
  153. E int FDECL(write, (int,char *,int));
  154. E int FDECL(link, (const char *, const char*));
  155. # else
  156. # ifndef bsdi
  157. E long FDECL(lseek, (int,long,int));
  158. # endif
  159. #  if defined(POSIX_TYPES) || defined(__TURBOC__)
  160. #   ifndef bsdi
  161. E int FDECL(write, (int, const void *,unsigned));
  162. #   endif
  163. #  else
  164. #   ifndef __MWERKS__	/* metrowerks defines write via universal headers */
  165. E int FDECL(write, (int,genericptr_t,unsigned));
  166. #   endif
  167. #  endif
  168. # endif /* ULTRIX */
  169.  
  170. # ifdef OS2_CSET2	/* IBM CSet/2 */
  171. #  ifdef OS2_CSET2_VER_1
  172. E int FDECL(unlink, (char *));
  173. #  else
  174. E int FDECL(unlink, (const char *)); /* prototype is ok in ver >= 2 */
  175. #  endif
  176. # else
  177. #  ifndef __SC__
  178. E int FDECL(unlink, (const char *));
  179. #  endif
  180. # endif
  181.  
  182. #endif /* AZTEC_50 && __GNUC__ */
  183.  
  184. #ifdef MAC
  185. #ifndef __CONDITIONALMACROS__	/* universal headers */
  186. E int FDECL(close, (int));		/* unistd.h */
  187. E int FDECL(read, (int, char *, int));	/* unistd.h */
  188. E int FDECL(chdir, (const char *));	/* unistd.h */
  189. E char *FDECL(getcwd, (char *,int));	/* unistd.h */
  190. #endif
  191.  
  192. E int FDECL(open, (const char *,int));
  193. #endif
  194.  
  195. #if defined(MICRO)
  196. E int FDECL(close, (int));
  197. #ifndef __EMX__
  198. E int FDECL(read, (int,genericptr_t,unsigned int));
  199. #endif
  200. E int FDECL(open, (const char *,int,...));
  201. E int FDECL(dup2, (int, int));
  202. E int FDECL(setmode, (int,int));
  203. E int NDECL(kbhit);
  204. # if !defined(_DCC)
  205. #  if defined(__TURBOC__)
  206. E int FDECL(chdir, (const char *));
  207. #  else
  208. #   ifndef __EMX__
  209. E int FDECL(chdir, (char *));
  210. #   endif
  211. #  endif
  212. #  ifndef __EMX__
  213. E char *FDECL(getcwd, (char *,int));
  214. #  endif
  215. # endif /* !_DCC */
  216. #endif
  217.  
  218. #ifdef ULTRIX
  219. E int FDECL(close, (int));
  220. E int FDECL(atoi, (const char *));
  221. E int FDECL(chdir, (const char *));
  222. # if !defined(ULTRIX_CC20) && !defined(__GNUC__)
  223. E int FDECL(chmod, (const char *,int));
  224. E mode_t FDECL(umask, (int));
  225. # endif
  226. E int FDECL(read, (int,genericptr_t,unsigned));
  227. /* these aren't quite right, but this saves including lots of system files */
  228. E int FDECL(stty, (int,genericptr_t));
  229. E int FDECL(gtty, (int,genericptr_t));
  230. E int FDECL(ioctl, (int, int, char*));
  231. E int FDECL(isatty, (int));	/* 1==yes, 0==no, -1==error */
  232. #include <sys/file.h>
  233. # if defined(ULTRIX_PROTO) || defined(__GNUC__)
  234. E int NDECL(fork);
  235. # else
  236. E long NDECL(fork);
  237. # endif
  238. #endif /* ULTRIX */
  239.  
  240. #ifdef VMS
  241. # ifndef abs
  242. E int FDECL(abs, (int));
  243. # endif
  244. E int FDECL(atexit, (void (*)(void)));
  245. E int FDECL(atoi, (const char *));
  246. E int FDECL(chdir, (const char *));
  247. E int FDECL(chown, (const char *,unsigned,unsigned));
  248. # ifdef __DECC_VER
  249. E int FDECL(chmod, (const char *,mode_t));
  250. E mode_t FDECL(umask, (mode_t));
  251. # else
  252. E int FDECL(chmod, (const char *,int));
  253. E int FDECL(umask, (int));
  254. # endif
  255. /* #include <unixio.h> */
  256. E int FDECL(close, (int));
  257. E int VDECL(creat, (const char *,unsigned,...));
  258. E int FDECL(delete, (const char *));
  259. E int FDECL(fstat, ( /*_ int, stat_t * _*/ ));
  260. E int FDECL(isatty, (int));	/* 1==yes, 0==no, -1==error */
  261. E long FDECL(lseek, (int,long,int));
  262. E int VDECL(open, (const char *,int,unsigned,...));
  263. E int FDECL(read, (int,genericptr_t,unsigned));
  264. E int FDECL(rename, (const char *,const char *));
  265. E int FDECL(stat, ( /*_ const char *,stat_t * _*/ ));
  266. E int FDECL(write, (int,const genericptr,unsigned));
  267. #endif
  268.  
  269. #endif	/* __SASC_60 */
  270.  
  271. /* both old & new versions of Ultrix want these, but real BSD does not */
  272. #ifdef ultrix
  273. E void abort();
  274. E void bcopy();
  275. # ifdef ULTRIX
  276. E int FDECL(system, (const char *));
  277. #  ifndef _UNISTD_H_
  278. E int FDECL(execl, (const char *, ...));
  279. #  endif
  280. # endif
  281. #endif
  282. #ifdef MICRO
  283. E void NDECL(abort);
  284. E void FDECL(_exit, (int));
  285. E int FDECL(system, (const char *));
  286. #endif
  287. #if defined(HPUX) && !defined(_POSIX_SOURCE)
  288. E long NDECL(fork);
  289. #endif
  290.  
  291. #ifdef POSIX_TYPES
  292. /* The POSIX string.h is required to define all the mem* and str* functions */
  293. #include <string.h>
  294. #else
  295. #if defined(SYSV) || defined(VMS) || defined(MAC) || defined(SUNOS4)
  296. # if defined(NHSTDC) || (defined(VMS) && !defined(ANCIENT_VAXC))
  297. #  if !defined(_AIX32) && !(defined(SUNOS4) && defined(__STDC__))
  298. 				/* Solaris unbundled cc (acc) */
  299. E int FDECL(memcmp, (const void *,const void *,size_t));
  300. E void *FDECL(memcpy, (void *, const void *, size_t));
  301. E void *FDECL(memset, (void *, int, size_t));
  302. #  endif
  303. # else
  304. #  ifndef memcmp	/* some systems seem to macro these back to b*() */
  305. E int memcmp();
  306. #  endif
  307. #  ifndef memcpy
  308. E char *memcpy();
  309. #  endif
  310. #  ifndef memset
  311. E char *memset();
  312. #  endif
  313. # endif
  314. #else
  315. # ifdef HPUX
  316. E int FDECL(memcmp, (char *,char *,int));
  317. E void *FDECL(memcpy, (char *,char *,int));
  318. E void *FDECL(memset, (char*,int,int));
  319. # endif
  320. #endif
  321. #endif /* POSIX_TYPES */
  322.  
  323. #if defined(MICRO) && !defined(LATTICE)
  324. # if defined(TOS) && defined(__GNUC__)
  325. E int FDECL(memcmp, (const void *,const void *,size_t));
  326. E void *FDECL(memcpy, (void *,const void *,size_t));
  327. E void *FDECL(memset, (void *,int,size_t));
  328. # else
  329. #  if defined(AZTEC_50) || defined(NHSTDC) || defined(WIN32)
  330. E int  FDECL(memcmp, (const void *, const void *, size_t));
  331. E void *FDECL(memcpy, (void *, const void *, size_t));
  332. E void *FDECL(memset, (void *, int, size_t));
  333. #  else
  334. E int FDECL(memcmp, (char *,char *,unsigned int));
  335. E char *FDECL(memcpy, (char *,char *,unsigned int));
  336. E char *FDECL(memset, (char*,int,int));
  337. #  endif /* AZTEC_50 || NHSTDC */
  338. # endif /* TOS */
  339. #endif /* MICRO */
  340.  
  341. #if defined(BSD) && defined(ultrix)	/* i.e., old versions of Ultrix */
  342. E void sleep();
  343. #endif
  344. #if defined(ULTRIX) || defined(SYSV)
  345. E unsigned sleep();
  346. #endif
  347. #if defined(HPUX)
  348. E unsigned int FDECL(sleep, (unsigned int));
  349. #endif
  350. #ifdef VMS
  351. E int FDECL(sleep, (unsigned));
  352. #endif
  353.  
  354. E char *FDECL(getenv, (const char *));
  355. E char *getlogin();
  356. #if defined(HPUX) && !defined(_POSIX_SOURCE)
  357. E long NDECL(getuid);
  358. E long NDECL(getgid);
  359. E long NDECL(getpid);
  360. #else
  361. # ifdef POSIX_TYPES
  362. E pid_t NDECL(getpid);
  363. E uid_t NDECL(getuid);
  364. E gid_t NDECL(getgid);
  365. #  ifdef VMS
  366. E pid_t NDECL(getppid);
  367. #  endif
  368. # else	/*!POSIX_TYPES*/
  369. #  ifndef getpid		/* Borland C defines getpid() as a macro */
  370. E int NDECL(getpid);
  371. #  endif
  372. #  ifdef VMS
  373. E int NDECL(getppid);
  374. E unsigned NDECL(getuid);
  375. E unsigned NDECL(getgid);
  376. #  endif
  377. #  if defined(ULTRIX) && !defined(_UNISTD_H_)
  378. E unsigned NDECL(getuid);
  379. E unsigned NDECL(getgid);
  380. E int FDECL(setgid, (int));
  381. E int FDECL(setuid, (int));
  382. #  endif
  383. # endif	/*?POSIX_TYPES*/
  384. #endif	/*?(HPUX && !_POSIX_SOURCE)*/
  385.  
  386. /* add more architectures as needed */
  387. #if defined(HPUX)
  388. #define seteuid(x) setreuid(-1, (x));
  389. #endif
  390.  
  391. /*# string(s).h #*/
  392. #if !defined(_XtIntrinsic_h) && !defined(POSIX_TYPES)
  393. /* <X11/Intrinsic.h> #includes <string[s].h>; so does defining POSIX_TYPES */
  394.  
  395. #if (defined(ULTRIX) || defined(NeXT)) && defined(__GNUC__)
  396. #include <strings.h>
  397. #else
  398. E char	*FDECL(strcpy, (char *,const char *));
  399. E char	*FDECL(strncpy, (char *,const char *,size_t));
  400. E char	*FDECL(strcat, (char *,const char *));
  401. E char	*FDECL(strncat, (char *,const char *,size_t));
  402. E char	*FDECL(strpbrk, (const char *,const char *));
  403.  
  404. # if defined(SYSV) || defined(MICRO) || defined(MAC) || defined(VMS) || defined(HPUX)
  405. E char	*FDECL(strchr, (const char *,int));
  406. E char	*FDECL(strrchr, (const char *,int));
  407. # else /* BSD */
  408. E char	*FDECL(index, (const char *,int));
  409. E char	*FDECL(rindex, (const char *,int));
  410. # endif
  411.  
  412. E int	FDECL(strcmp, (const char *,const char *));
  413. E int	FDECL(strncmp, (const char *,const char *,size_t));
  414. # if defined(MICRO) || defined(MAC) || defined(VMS)
  415. E size_t FDECL(strlen, (const char *));
  416. # else
  417. # ifdef HPUX
  418. E unsigned int	FDECL(strlen, (char *));
  419. #  else
  420. #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
  421. E int	FDECL(strlen, (const char *));
  422. #   endif
  423. #  endif /* HPUX */
  424. # endif /* MICRO */
  425. #endif /* ULTRIX */
  426.  
  427. #endif	/* !_XtIntrinsic_h_ && !POSIX_TYPES */
  428.  
  429. #if defined(ULTRIX) && defined(__GNUC__)
  430. E char	*FDECL(index, (const char *,int));
  431. E char	*FDECL(rindex, (const char *,int));
  432. #endif
  433.  
  434. /* Old varieties of BSD have char *sprintf().
  435. * Newer varieties of BSD have int sprintf() but allow for the old char *.
  436. * Several varieties of SYSV and PC systems also have int sprintf().
  437. * If your system doesn't agree with this breakdown, you may want to change
  438. * this declaration, especially if your machine treats the types differently.
  439. * If your system defines sprintf, et al, in stdio.h, add to the initial
  440. * #if.
  441. */
  442. #if defined(ULTRIX) || defined(__DECC) || defined(__SASC_60) || defined(WIN32)
  443. #define SPRINTF_PROTO
  444. #endif
  445. #if (defined(SUNOS4) && defined(__STDC__)) || defined(_AIX32)
  446. #define SPRINTF_PROTO
  447. #endif
  448. #if defined(TOS) || defined(AZTEC_50) || defined(__sgi) || defined(__GNUC__)
  449. 	/* problem with prototype mismatches */
  450. #define SPRINTF_PROTO
  451. #endif
  452. #if defined(__MWERKS__) || defined(__SC__)
  453. 	/* Metrowerks already has a prototype for sprintf() */
  454. # define SPRINTF_PROTO
  455. #endif
  456.  
  457. #ifndef SPRINTF_PROTO
  458. # if defined(POSIX_TYPES) || defined(DGUX) || defined(NeXT) || !defined(BSD)
  459. E  int FDECL(sprintf, (char *,const char *,...));
  460. # else
  461. #  define OLD_SPRINTF
  462. E  char *sprintf();
  463. # endif
  464. #endif
  465. #ifdef SPRINTF_PROTO
  466. # undef SPRINTF_PROTO
  467. #endif
  468.  
  469. #ifndef __SASC_60
  470. #ifdef NEED_VARARGS
  471. # if defined(USE_STDARG) || defined(USE_VARARGS)
  472. #  if !defined(SVR4) && !defined(apollo)
  473. #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
  474. #    if !(defined(SUNOS4) && defined(__STDC__)) /* Solaris unbundled cc (acc) */
  475. E int FDECL(vsprintf, (char *, const char *, va_list));
  476. E int FDECL(vfprintf, (FILE *, const char *, va_list));
  477. E int FDECL(vprintf, (const char *, va_list));
  478. #    endif
  479. #   endif
  480. #  endif
  481. # else
  482. #  define vprintf	printf
  483. #  define vfprintf	fprintf
  484. #  define vsprintf	sprintf
  485. # endif
  486. #endif /* NEED_VARARGS */
  487. #endif
  488.  
  489.  
  490. #ifdef MICRO
  491. E int FDECL(tgetent, (const char *,const char *));
  492. E void FDECL(tputs, (const char *,int,int (*)()));
  493. E int FDECL(tgetnum, (const char *));
  494. E int FDECL(tgetflag, (const char *));
  495. E char *FDECL(tgetstr, (const char *,char **));
  496. E char *FDECL(tgoto, (const char *,int,int));
  497. #else
  498. # if ! (defined(HPUX) && defined(_POSIX_SOURCE))
  499. E int FDECL(tgetent, (char *,const char *));
  500. E void FDECL(tputs, (const char *,int,int (*)()));
  501. # endif
  502. E int FDECL(tgetnum, (const char *));
  503. E int FDECL(tgetflag, (const char *));
  504. E char *FDECL(tgetstr, (const char *,char **));
  505. E char *FDECL(tgoto, (const char *,int,int));
  506. #endif
  507.  
  508. #ifdef ALLOC_C
  509. E genericptr_t FDECL(malloc, (size_t));
  510. #endif
  511.  
  512. /* time functions */
  513.  
  514. # ifndef LATTICE
  515. #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
  516. E struct tm *FDECL(localtime, (const time_t *));
  517. #  endif
  518. # endif
  519.  
  520. # if defined(ULTRIX) || (defined(BSD) && defined(POSIX_TYPES)) || defined(SYSV) || defined(MICRO) || defined(VMS) || defined(MAC) || (defined(HPUX) && defined(_POSIX_SOURCE))
  521. E time_t FDECL(time, (time_t *));
  522. # else
  523. E long FDECL(time, (time_t *));
  524. # endif /* ULTRIX */
  525.  
  526. #ifdef VMS
  527. 	/* used in makedefs.c, but missing from gcc-vms's <time.h> */
  528. E char *FDECL(ctime, (const time_t *));
  529. #endif
  530.  
  531.  
  532. #ifdef MICRO
  533. # ifdef abs
  534. # undef abs
  535. # endif
  536. E int FDECL(abs, (int));
  537. # ifdef atoi
  538. # undef atoi
  539. # endif
  540. E int FDECL(atoi, (const char *));
  541. #endif
  542.  
  543. #undef E
  544.  
  545. #endif /*  !__cplusplus && !__GO32__ */
  546.  
  547. #endif /* SYSTEM_H */