home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / borhead.zip / STDLIB.H < prev    next >
C/C++ Source or Header  |  1994-11-09  |  11KB  |  350 lines

  1. /*  stdlib.h
  2.  
  3.     Definitions for common types, variables, and functions.
  4.  
  5. */
  6.  
  7. /*
  8.  *      C/C++ Run Time Library - Version 1.5
  9.  *
  10.  *      Copyright (c) 1987, 1994 by Borland International
  11.  *      All Rights Reserved.
  12.  *
  13.  */
  14.  
  15. #ifndef __STDLIB_H
  16. #define __STDLIB_H
  17.  
  18. #if !defined(___DEFS_H)
  19. #include <_defs.h>
  20. #endif
  21.  
  22. #ifndef NULL
  23. #include <_null.h>
  24. #endif
  25.  
  26.  
  27. #if !defined(RC_INVOKED)
  28.  
  29. #if defined(__STDC__)
  30. #pragma warn -nak
  31. #endif
  32.  
  33. #pragma option -a-
  34.  
  35. #endif  /* !RC_INVOKED */
  36.  
  37.  
  38. #ifndef _SIZE_T
  39. #define _SIZE_T
  40. typedef unsigned size_t;
  41. #endif
  42.  
  43. #ifndef _DIV_T
  44. #define _DIV_T
  45. typedef struct {
  46.         int     quot;
  47.         int     rem;
  48. } div_t;
  49. #endif
  50.  
  51. #ifndef _LDIV_T
  52. #define _LDIV_T
  53. typedef struct {
  54.         long    quot;
  55.         long    rem;
  56. } ldiv_t;
  57. #endif
  58.  
  59. #ifndef __cplusplus
  60. #ifndef _WCHAR_T
  61. #define _WCHAR_T
  62. typedef unsigned short wchar_t;
  63. #endif
  64. #endif
  65.  
  66. #define MB_CUR_MAX 1
  67.  
  68. /* Maximum value returned by "rand" function
  69. */
  70. #define RAND_MAX 0x7FFFU
  71.  
  72. #define EXIT_SUCCESS 0
  73. #define EXIT_FAILURE 1
  74.  
  75. typedef void (_USERENTRY * atexit_t)(void);
  76.  
  77. /*
  78.   These 2 constants are defined in MS's stdlib.h.
  79. */
  80.  
  81. #define DOS_MODE    0  /* DOS 16-bit */
  82. #define OS2_MODE    1  /* OS/2 16-bit */
  83.  
  84.  
  85.  
  86. #ifdef __cplusplus
  87. extern "C" {
  88. #endif
  89.  
  90. void        _RTLENTRY _EXPFUNC abort(void);
  91.  
  92. #if !defined(__ABS_DEFINED)
  93. #define __ABS_DEFINED
  94.  
  95. int         _RTLENTRY __abs__(int);
  96. #ifdef __cplusplus
  97. inline int _RTLENTRY  abs(int __x) { return __abs__(__x); }
  98. #else
  99. int         _RTLENTRYF _EXPFUNC abs(int __x);
  100. #  define abs(x)   __abs__(x)
  101. #endif
  102.  
  103. #endif /* __ABS_DEFINED */
  104.  
  105. int         _RTLENTRY   _EXPFUNC atexit(void (_USERENTRY * __func)(void));
  106. double      _RTLENTRY   _EXPFUNC atof(const char * __s);
  107. int         _RTLENTRYF  _EXPFUNC atoi(const char * __s);
  108. long        _RTLENTRYF  _EXPFUNC atol(const char * __s);
  109. void *      _RTLENTRYF  _EXPFUNC bsearch(const void * __key, const void * __base,
  110.                            size_t __nelem, size_t __width,
  111.                            int (_USERENTRY *fcmp)(const void *,
  112.                            const void *));
  113. void *      _RTLENTRY _EXPFUNC   calloc(size_t __nitems, size_t __size);
  114. div_t       _RTLENTRY _EXPFUNC   div(int __numer, int __denom);
  115. void        _RTLENTRY _EXPFUNC   exit(int __status);
  116. void        _RTLENTRY _EXPFUNC   free(void * __block);
  117. char *      _RTLENTRYF _EXPFUNC  getenv(const char * __name);
  118. long        _RTLENTRY _EXPFUNC   labs(long __x);
  119. ldiv_t      _RTLENTRY _EXPFUNC   ldiv(long __numer, long __denom);
  120. void *      _RTLENTRY _EXPFUNC   malloc(size_t __size);
  121. int         _RTLENTRY _EXPFUNC   mblen(const char * __s, size_t __n);
  122. size_t      _RTLENTRY _EXPFUNC   mbstowcs(wchar_t *__pwcs, const char * __s,
  123.                            size_t __n);
  124. int         _RTLENTRY _EXPFUNC   mbtowc(wchar_t *__pwc, const char * __s, size_t __n);
  125. void        _RTLENTRYF _EXPFUNC  qsort(void * __base, size_t __nelem, size_t __width,
  126.                            int (_USERENTRY *__fcmp)(const void *, const void *));
  127. int         _RTLENTRY _EXPFUNC   rand(void);
  128. void *      _RTLENTRY _EXPFUNC   realloc(void * __block, size_t __size);
  129. void        _RTLENTRY _EXPFUNC   srand(unsigned __seed);
  130. double      _RTLENTRY _EXPFUNC   strtod(const char * __s, char * *__endptr);
  131. long        _RTLENTRY _EXPFUNC   strtol(const char * __s, char * *__endptr,
  132.                            int __radix);
  133. long double _RTLENTRY _EXPFUNC   _strtold(const char * __s, char * *__endptr);
  134. unsigned long _RTLENTRY _EXPFUNC strtoul(const char * __s, char * *__endptr,
  135.                            int __radix);
  136. int         _RTLENTRY _EXPFUNC   system(const char * __command);
  137. size_t      _RTLENTRY _EXPFUNC   wcstombs(char * __s, const wchar_t *__pwcs,
  138.                            size_t __n);
  139. int         _RTLENTRY _EXPFUNC   wctomb(char * __s, wchar_t __wc);
  140.  
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144.  
  145. /* Variables */
  146.  
  147. #ifdef _MT
  148.  
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. extern  int * _RTLENTRY _EXPFUNC __errno(void);
  153. extern  int * _RTLENTRY _EXPFUNC __doserrno(void);
  154. #ifdef  __cplusplus
  155. }
  156. #endif
  157. #define errno (*__errno())
  158. #define _doserrno (*__doserrno())
  159.  
  160. #else   /* MT */
  161.  
  162. extern  int   _RTLENTRY _EXPDATA errno;
  163. extern  int   _RTLENTRY _EXPDATA _doserrno;
  164.  
  165. #endif  /* MT */
  166.  
  167. #if !defined(__STDC__)
  168.  
  169. /* Values for _osmode */
  170.  
  171. #define _WIN_MODE    2  /* Windows 16- or 32-bit */
  172. #define _OS2_20_MODE 3  /* OS/2 32-bit */
  173. #define _DOSX32_MODE 4  /* DOS 32-bit */
  174.  
  175. #define environ  _environ
  176.  
  177. #endif /* __STDC__ */
  178.  
  179. extern  char          **_RTLENTRY _EXPDATA _environ;
  180. extern  int             _RTLENTRY _EXPDATA _fileinfo;
  181. extern  int             _RTLENTRY          _fmode;
  182. extern  unsigned char   _RTLENTRY _EXPDATA _osmajor;
  183. extern  unsigned char   _RTLENTRY _EXPDATA _osminor;
  184. extern  unsigned char   _RTLENTRY _EXPDATA _osmode;
  185. extern  unsigned int    _RTLENTRY _EXPDATA _osversion;
  186.  
  187. #if !defined(__STDC__)
  188. #ifdef __cplusplus
  189.    inline int _RTLENTRY atoi(const char *__s) { return (int)atol(__s); }
  190. #else
  191. #  define atoi(s)((int) atol(s))
  192. #endif
  193. #endif
  194.  
  195. #if !__STDC__
  196. #define sys_nerr     _sys_nerr
  197. #define sys_errlist  _sys_errlist
  198. #endif
  199.  
  200. extern  char          * _RTLENTRY _EXPDATA _sys_errlist[];
  201. extern  int             _RTLENTRY _EXPDATA _sys_nerr;
  202.  
  203.  
  204. /* Constants for MSC pathname functions */
  205.  
  206. #define _MAX_PATH       260
  207. #define _MAX_DRIVE      3
  208. #define _MAX_DIR        256
  209. #define _MAX_FNAME      256
  210. #define _MAX_EXT        256
  211.  
  212. #ifdef __cplusplus
  213. extern "C" {
  214. #endif
  215.  
  216. long double   _RTLENTRY  _EXPFUNC _atold(const char * __s);
  217.  
  218. unsigned char _RTLENTRY  _EXPFUNC _crotl(unsigned char __value, int __count);
  219. unsigned char _RTLENTRY  _EXPFUNC _crotr(unsigned char __value, int __count);
  220.  
  221. char *        _RTLENTRY  _EXPFUNC ecvt(double __value, int __ndig, int * __dec,
  222.                                        int * __sign);
  223. void          _RTLENTRY  _EXPFUNC _exit(int __status);
  224. char *        _RTLENTRY  _EXPFUNC fcvt(double __value, int __ndig, int * __dec,
  225.                                        int * __sign);
  226. char *        _RTLENTRYF _EXPFUNC _fullpath(char * __buf, const char * __path,
  227.                                             size_t __maxlen);
  228. char *        _RTLENTRY  _EXPFUNC gcvt(double __value, int __ndec,
  229.                                        char * __buf);
  230. char *        _RTLENTRYF _EXPFUNC itoa(int __value, char * __string,
  231.                                        int __radix);
  232. void *        _RTLENTRY  _EXPFUNC lfind(const void * __key,
  233.                                         const void * __base,
  234.                                         size_t *__num, size_t __width,
  235.                                         int (_USERENTRY *fcmp)(const void *, const void *));
  236.  
  237. long          _RTLENTRY  _EXPFUNC _lrand(void);
  238. unsigned long _RTLENTRY  _EXPFUNC _lrotl(unsigned long __val, int __count);
  239. unsigned long _RTLENTRY  _EXPFUNC _lrotr(unsigned long __val, int __count);
  240.  
  241. void *        _RTLENTRY  _EXPFUNC lsearch(const void * __key, void * __base,
  242.                                           size_t *__num, size_t __width,
  243.                                           int (_USERENTRY *fcmp)(const void *, const void *));
  244.  
  245. char *        _RTLENTRYF _EXPFUNC ltoa(long __value, char * __string,
  246.                                        int __radix);
  247. void          _RTLENTRY  _EXPFUNC _makepath(char * __path,
  248.                                             const char * __drive,
  249.                                             const char * __dir,
  250.                                             const char * __name,
  251.                                             const char * __ext );
  252. int           _RTLENTRY  _EXPFUNC putenv(const char * __name);
  253.  
  254. unsigned short _RTLENTRY _EXPFUNC _rotl(unsigned short __value, int __count);
  255. unsigned short _RTLENTRY _EXPFUNC _rotr(unsigned short __value, int __count);
  256.  
  257. void          _RTLENTRY  _EXPFUNC _searchenv(const char * __file,
  258.                                              const char * __varname,
  259.                                              char *__pathname);
  260. void          _RTLENTRY  _EXPFUNC _searchstr(const char * __file,
  261.                                              const char * __ipath,
  262.                                              char *__pathname);
  263. void          _RTLENTRY  _EXPFUNC _splitpath(const char * __path,
  264.                                              char * __drive,
  265.                                              char * __dir,
  266.                                              char * __name,
  267.                                              char * __ext );
  268. void          _RTLENTRY  _EXPFUNC swab(char * __from, char * __to, int __nbytes);
  269. char *        _RTLENTRYF _EXPFUNC ultoa(unsigned long __value, char * __string,
  270.                                         int __radix);
  271.  
  272. /* Intrinsic functions */
  273.  
  274. unsigned char _RTLENTRY  ___crotl__(unsigned char __value, int __count);
  275. unsigned char _RTLENTRY  ___crotr__(unsigned char __value, int __count);
  276. unsigned long _RTLENTRY  ___lrotl__(unsigned long __val, int __count);
  277. unsigned long _RTLENTRY  ___lrotr__(unsigned long __val, int __count);
  278. unsigned short _RTLENTRY ___rotl__ (unsigned short __value, int __count);
  279. unsigned short _RTLENTRY ___rotr__ (unsigned short __value, int __count);
  280.  
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284.  
  285. #if !defined(__STDC__)
  286.  
  287. #if defined(__cplusplus)
  288. inline int  _RTLENTRY random(int __num)
  289.                        { return __num ? (int)(_lrand()%(__num)) : 0; }
  290. #else /* __cplusplus */
  291. #define random(num) (num ? (int)(_lrand()%(num)) : 0)
  292. #endif  /* __cplusplus  */
  293.  
  294. #endif /* __STDC__ */
  295.  
  296.  
  297. #if defined(__cplusplus)
  298. extern "C" long _RTLENTRY _EXPFUNC time(long _FAR *);
  299. #endif
  300.  
  301. #if !defined(__STDC__)
  302.  
  303. #if defined(__cplusplus)
  304.  
  305. /* Need prototype of time() for C++ randomize() */
  306. inline void _RTLENTRY randomize(void) { srand((unsigned) time(NULL)); }
  307.  
  308. #ifndef __MINMAX_DEFINED
  309. #define __MINMAX_DEFINED
  310. template <class T> inline const T& min( const T& t1, const T& t2 )
  311. {
  312.     return t1>t2 ? t2 : t1;
  313. }
  314.  
  315. template <class T> inline const T& max( const T& t1, const T& t2 )
  316. {
  317.     return t1>t2 ? t1 : t2;
  318. }
  319. #endif
  320.  
  321. #else /* __cplusplus */
  322.  
  323. #define randomize() srand((unsigned)time(NULL))
  324. #define max(a,b)    (((a) > (b)) ? (a) : (b))
  325. #define min(a,b)    (((a) < (b)) ? (a) : (b))
  326. #endif
  327.  
  328. #define  MB_CUR_MAX              1
  329.  
  330. #endif /* __STDC__ */
  331.  
  332. #if defined(__MSC)
  333. #define _itoa(__value, __string, __radix) itoa(__value, __string, __radix)
  334. #endif
  335.  
  336.  
  337. #if !defined(RC_INVOKED)
  338.  
  339. #pragma option -a.  /* restore default packing */
  340.  
  341. #if defined(__STDC__)
  342. #pragma warn .nak
  343. #endif
  344.  
  345. #endif  /* !RC_INVOKED */
  346.  
  347.  
  348. #endif  /* __STDLIB_H */
  349.  
  350.