home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL3.ZIP / PATINC.ZIP / STDLIB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  7.0 KB  |  234 lines

  1. /*      stdlib.h
  2.  
  3.         Definitions for common types, variables, and functions.
  4.  
  5.         Copyright (c) Borland International 1987,1988,1990,1991
  6.         All Rights Reserved.
  7. */
  8.  
  9. #ifndef __STDLIB_H
  10. #define __STDLIB_H
  11.  
  12. #if !defined( __DEFS_H )
  13. #include <_defs.h>
  14. #endif
  15.  
  16. #ifndef _SIZE_T
  17. #define _SIZE_T
  18. typedef unsigned size_t;
  19. #endif
  20.  
  21. #ifndef _DIV_T
  22. #define _DIV_T
  23. typedef struct {
  24.         int     quot;
  25.         int     rem;
  26. } div_t;
  27. #endif
  28.  
  29. #ifndef _LDIV_T
  30. #define _LDIV_T
  31. typedef struct {
  32.         long    quot;
  33.         long    rem;
  34. } ldiv_t;
  35. #endif
  36.  
  37. #ifndef _WCHAR_T
  38. #define _WCHAR_T
  39. typedef char wchar_t;
  40. #endif
  41.  
  42. #ifndef NULL
  43. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  44. #define NULL    0
  45. #else
  46. #define NULL    0L
  47. #endif
  48. #endif
  49.  
  50. typedef void _Cdecl (_FAR * atexit_t)(void);
  51.  
  52. /* Maximum value returned by "rand" function
  53. */
  54. #define RAND_MAX 0x7FFFU
  55.  
  56. #define EXIT_SUCCESS 0
  57. #define EXIT_FAILURE 1
  58.  
  59. #define MB_CUR_MAX 1
  60.  
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. void    _Cdecl abort(void);
  65. int     _Cdecl atexit(atexit_t __func);
  66. double  _Cdecl atof(const char *__s);
  67. int     _Cdecl _FARFUNC atoi(const char _FAR *__s);
  68. long    _CType _FARFUNC atol(const char _FAR *__s);
  69. void   _FAR *_CType _FARFUNC bsearch(const void _FAR *__key, const void _FAR *__base, 
  70.                 size_t __nelem, size_t __width,
  71.                 int _Cdecl(* _FARFUNC __fcmp)(const void _FAR *, const void _FAR *));
  72. void   _FAR *_Cdecl _FARFUNC calloc(size_t __nitems, size_t __size);
  73. div_t   _Cdecl div(int __numer, int __denom);
  74. void    _Cdecl exit(int __status);
  75. void    _Cdecl _FARFUNC free(void _FAR *__block);
  76. char   _FAR *_Cdecl _FARFUNC getenv(const char _FAR *__name);
  77. int     _Cdecl abs(int __x);
  78. long    _Cdecl labs(long __x);
  79. ldiv_t  _Cdecl _FARFUNC ldiv(long __numer, long __denom);
  80. void   _FAR *_Cdecl _FARFUNC malloc(size_t __size);
  81. int     _Cdecl _FARFUNC mblen(const char _FAR *__s, size_t __n);
  82. size_t  _Cdecl _FARFUNC mbstowcs(wchar_t _FAR *__pwcs, const char _FAR *__s,
  83.                         size_t __n);
  84. int     _Cdecl _FARFUNC mbtowc(wchar_t _FAR *__pwc, const char _FAR *__s, size_t __n);
  85. void    _Cdecl _FARFUNC qsort(void _FAR *__base, size_t __nelem, size_t __width,
  86.                 int _Cdecl(*_FARFUNC __fcmp)(const void _FAR *, const void _FAR *));
  87. int     _Cdecl rand(void);
  88. void   _FAR *_Cdecl _FARFUNC realloc(void _FAR *__block, size_t __size);
  89. void    _Cdecl srand(unsigned __seed);
  90. double  _Cdecl _FARFUNC strtod(const char _FAR *__s, char _FAR *_FAR *__endptr);
  91. long    _Cdecl _FARFUNC strtol(const char _FAR *__s, char _FAR *_FAR *__endptr,
  92.                       int __radix);
  93. unsigned long _Cdecl _FARFUNC strtoul(const char _FAR *__s, char _FAR *_FAR *__endptr,
  94.                              int __radix);
  95. int     _Cdecl _FARFUNC system(const char _FAR *__command);
  96. size_t  _Cdecl _FARFUNC wcstombs(char _FAR *__s, const wchar_t _FAR *__pwcs,
  97.                         size_t __n);
  98. int     _Cdecl _FARFUNC wctomb(char _FAR *__s, wchar_t __wc);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102.  
  103. #if !__STDC__
  104.  
  105. /* Variables */
  106. #if !defined( _RTLDLL )
  107. extern  int _Cdecl  errno;
  108. extern  int _Cdecl  _doserrno;
  109. #else
  110.  
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. int far * far _Cdecl __getErrno(void);
  115. int far * far _Cdecl __getDOSErrno(void);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119.  
  120. #define errno (*__getErrno())
  121. #define _doserrno (*__getDOSErrno())
  122. #endif
  123.  
  124. /*
  125.   These 2 constants are defined in MS's stdlib.h.  Rather than defining them
  126.   all the time and invading the ANSI programmers name space we'll only make
  127.   them visible when __STDC__ is *off*.  Anybody using these constants ain't
  128.   writing standard C anyway!
  129. */
  130. #define DOS_MODE  0
  131. #define OS2_MODE  1
  132.  
  133. extern  unsigned        _Cdecl _psp;
  134.  
  135. extern  char          **_Cdecl environ;
  136. extern  int             _Cdecl _fmode;
  137. extern  unsigned char   _Cdecl _osmajor;
  138. extern  unsigned char   _Cdecl _osminor;
  139. extern  char           _FAR *_Cdecl sys_errlist[];
  140. extern  int             _Cdecl sys_nerr;
  141. extern  unsigned int    _Cdecl _version;
  142.  
  143. #define atoi(s)((int) atol(s))
  144.  
  145. #ifdef __cplusplus
  146. inline int  _Cdecl random(int __num)
  147.     { return(int)(((long)rand()*__num)/(RAND_MAX+1)); }
  148. extern "C" long _Cdecl _FARFUNC time(long _FAR *);  /* need prototype of time() for C++ randomize() */
  149. inline void _Cdecl randomize(void) { srand((unsigned) time(NULL)); }
  150. #else
  151. #define random(num)(int)(((long)rand()*(num))/(RAND_MAX+1))
  152. #define randomize()     srand((unsigned)time(NULL))
  153. #define max(a,b)    (((a) > (b)) ? (a) : (b))
  154. #define min(a,b)    (((a) < (b)) ? (a) : (b))
  155. #endif
  156.  
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160. char   _FAR *_Cdecl ecvt(double __value, int __ndig, int _FAR *__dec, 
  161.                          int _FAR *__sign);
  162. void    _Cdecl _exit(int __status);
  163. char   _FAR *_Cdecl fcvt(double __value, int __ndig, int _FAR *__dec,
  164.                     int _FAR *__sign);
  165. char   *_Cdecl gcvt(double __value, int __ndec, char *__buf);
  166. char   _FAR *_CType _FARFUNC itoa(int __value, char _FAR *__string, int __radix);
  167. void   _FAR *_Cdecl _FARFUNC lfind(const void _FAR *__key, const void _FAR *__base, 
  168.                  size_t _FAR *__num, size_t __width,
  169.                  int _Cdecl(*_FARFUNC __fcmp)(const void _FAR *, const void _FAR *));
  170.  
  171. unsigned long _Cdecl _lrotl(unsigned long __val, int __count);
  172. unsigned long _Cdecl _lrotr(unsigned long __val, int __count);
  173.  
  174. void   _FAR *_Cdecl _FARFUNC lsearch(const void _FAR *__key, void _FAR *__base, 
  175.                  size_t _FAR *__num, size_t __width, 
  176.                  int _Cdecl(*_FARFUNC __fcmp)(const void _FAR *, const void _FAR *));
  177. char   _FAR *_Cdecl _FARFUNC ltoa(long __value, char _FAR *__string, int __radix);
  178. int     _Cdecl _FARFUNC putenv(const char _FAR *__name);
  179.  
  180. unsigned _Cdecl _rotl(unsigned __value, int __count);
  181. unsigned _Cdecl _rotr(unsigned __value, int __count);
  182.  
  183. void    _Cdecl _FARFUNC swab(char _FAR *__from, char _FAR *__to, int __nbytes);
  184. char   _FAR *_Cdecl _FARFUNC ultoa(unsigned long __value, char _FAR *__string,
  185.                           int __radix);
  186.  
  187. #ifdef __MSC
  188.  
  189. /* Prototypes needed for MSC macros */
  190.  
  191. int         _CType _FARFUNC fnsplit( const char _FAR *__path,
  192.                             char *__drive, char *__dir, 
  193.                             char _FAR *__name,
  194.                             char _FAR *__ext );
  195. #endif  /* __MSC */
  196.  
  197. #ifdef __cplusplus
  198. }
  199. #endif
  200.  
  201.  
  202. #endif  /* !__STDC__ */
  203.  
  204. #ifdef __MSC
  205.  
  206. /* MSC variables */
  207.  
  208. extern  unsigned      _Cdecl _version;
  209. #define _osversion _version
  210.  
  211. /* Constants for MSC functions */
  212.  
  213. #define _MAX_PATH   80
  214. #define _MAX_DRIVE  3
  215. #define _MAX_DIR    66
  216. #define _MAX_FNAME  9
  217. #define _MAX_EXT    5
  218.  
  219. /* Macros for MSC functions */
  220.  
  221. #define _splitpath(path,drive,dir,fname,ext) \
  222.   (void)fnsplit(path,drive,dir,fname,ext)
  223.  
  224. #endif  /* __MSC */
  225.  
  226. int _Cdecl __abs__(int);
  227. #ifdef __cplusplus
  228. inline int _Cdecl abs(int __x) { return __abs__(__x); }
  229. #else
  230. #define abs(x)          __abs__(x)
  231. #endif
  232.  
  233. #endif
  234.