home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / include / stdlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  13.7 KB  |  533 lines

  1. /*
  2.  * stdlib.h
  3.  *
  4.  * Definitions for common types, variables, and functions.
  5.  *
  6.  * This file is part of the Mingw32 package.
  7.  *
  8.  * Contributors:
  9.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  10.  *
  11.  *  THIS SOFTWARE IS NOT COPYRIGHTED
  12.  *
  13.  *  This source code is offered for use in the public domain. You may
  14.  *  use, modify or distribute it freely.
  15.  *
  16.  *  This code is distributed in the hope that it will be useful but
  17.  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18.  *  DISCLAIMED. This includes but is not limited to warranties of
  19.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * $Revision: 1.15 $
  22.  * $Author: earnie $
  23.  * $Date: 2003/02/08 14:31:38 $
  24.  *
  25.  */
  26.  
  27. #ifndef _STDLIB_H_
  28. #define _STDLIB_H_
  29.  
  30. /* All the headers include this file. */
  31. #include <_mingw.h>
  32.  
  33.  
  34. #define __need_size_t
  35. #define __need_wchar_t
  36. #define __need_NULL
  37. #ifndef RC_INVOKED
  38. #include <stddef.h>
  39. #endif /* RC_INVOKED */
  40.  
  41. /*
  42.  * RAND_MAX is the maximum value that may be returned by rand.
  43.  * The minimum is zero.
  44.  */
  45. #define    RAND_MAX    0x7FFF
  46.  
  47. /*
  48.  * These values may be used as exit status codes.
  49.  */
  50. #define    EXIT_SUCCESS    0
  51. #define    EXIT_FAILURE    1
  52.  
  53. /*
  54.  * Definitions for path name functions.
  55.  * NOTE: All of these values have simply been chosen to be conservatively high.
  56.  *       Remember that with long file names we can no longer depend on
  57.  *       extensions being short.
  58.  */
  59. #ifndef __STRICT_ANSI__
  60.  
  61. #ifndef MAX_PATH
  62. #define    MAX_PATH    (260)
  63. #endif
  64.  
  65. #define    _MAX_PATH    MAX_PATH
  66. #define    _MAX_DRIVE    (3)
  67. #define    _MAX_DIR    256
  68. #define    _MAX_FNAME    256
  69. #define    _MAX_EXT    256
  70.  
  71. #endif    /* Not __STRICT_ANSI__ */
  72.  
  73.  
  74. #ifndef RC_INVOKED
  75.  
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79.  
  80. /*
  81.  * This seems like a convenient place to declare these variables, which
  82.  * give programs using WinMain (or main for that matter) access to main-ish
  83.  * argc and argv. environ is a pointer to a table of environment variables.
  84.  * NOTE: Strings in _argv and environ are ANSI strings.
  85.  */
  86. extern int    _argc;
  87. extern char**    _argv;
  88.  
  89. /* imports from runtime dll of the above variables */
  90. #ifdef __MSVCRT__
  91.  
  92. extern int*     __p___argc(void);
  93. extern char***   __p___argv(void);
  94. extern wchar_t***   __p___wargv(void);
  95.  
  96. #define __argc (*__p___argc())
  97. #define __argv (*__p___argv())
  98. #define __wargv (*__p___wargv())
  99.  
  100. #else /* !MSVCRT */
  101.  
  102. #ifndef __DECLSPEC_SUPPORTED
  103.  
  104. extern int*    _imp____argc_dll;
  105. extern char***  _imp____argv_dll;
  106. #define __argc (*_imp____argc_dll)
  107. #define __argv (*_imp____argv_dll)
  108.  
  109. #else /* __DECLSPEC_SUPPORTED */
  110.  
  111. __MINGW_IMPORT int    __argc_dll;
  112. __MINGW_IMPORT char**  __argv_dll;
  113. #define __argc __argc_dll
  114. #define __argv __argv_dll
  115.  
  116. #endif /* __DECLSPEC_SUPPORTED */
  117.  
  118. #endif /* __MSVCRT */
  119.  
  120. /*
  121.  * Also defined in ctype.h.
  122.  */
  123. #ifndef MB_CUR_MAX
  124. #ifdef __DECLSPEC_SUPPORTED
  125. # ifdef __MSVCRT__
  126. #  define MB_CUR_MAX __mb_cur_max
  127.    __MINGW_IMPORT int __mb_cur_max;
  128. # else        /* not __MSVCRT */
  129. #  define MB_CUR_MAX __mb_cur_max_dll
  130.    __MINGW_IMPORT int __mb_cur_max_dll;
  131. # endif        /* not __MSVCRT */
  132.  
  133. #else        /* ! __DECLSPEC_SUPPORTED */
  134. # ifdef __MSVCRT__
  135.    extern int* _imp____mbcur_max;
  136. #  define MB_CUR_MAX (*_imp____mb_cur_max)
  137. # else        /* not __MSVCRT */
  138.    extern int*  _imp____mbcur_max_dll;
  139. #  define MB_CUR_MAX (*_imp____mb_cur_max_dll)
  140. # endif     /* not __MSVCRT */
  141. #endif      /*  __DECLSPEC_SUPPORTED */
  142. #endif  /* MB_CUR_MAX */
  143.  
  144. /* 
  145.  * MS likes to declare errno in stdlib.h as well. 
  146.  */
  147.  
  148. #ifdef _UWIN
  149. #undef errno
  150. extern int errno;
  151. #else
  152. int*    _errno(void);
  153. #define    errno        (*_errno())
  154. #endif
  155. int*    __doserrno(void);
  156. #define    _doserrno    (*__doserrno())
  157.  
  158. /*
  159.  * Use environ from the DLL, not as a global. 
  160.  */
  161.  
  162. #ifdef __MSVCRT__
  163.   extern char *** __p__environ(void);
  164.   extern wchar_t *** __p__wenviron(void);
  165. # define _environ (*__p__environ())
  166. # define _wenviron (*__p__wenviron())
  167. #else /* ! __MSVCRT__ */
  168. # ifndef __DECLSPEC_SUPPORTED
  169.     extern char *** _imp___environ_dll;
  170. #   define _environ (*_imp___environ_dll)
  171. # else /* __DECLSPEC_SUPPORTED */
  172.     __MINGW_IMPORT char ** _environ_dll;
  173. #   define _environ _environ_dll
  174. # endif /* __DECLSPEC_SUPPORTED */
  175. #endif /* ! __MSVCRT__ */
  176.  
  177. #define environ _environ
  178.  
  179. #ifdef    __MSVCRT__
  180. /* One of the MSVCRTxx libraries */
  181.  
  182. #ifndef __DECLSPEC_SUPPORTED
  183.   extern int*    _imp___sys_nerr;
  184. # define    sys_nerr    (*_imp___sys_nerr)
  185. #else /* __DECLSPEC_SUPPORTED */
  186.   __MINGW_IMPORT int    _sys_nerr;
  187. # ifndef _UWIN
  188. #   define    sys_nerr    _sys_nerr
  189. # endif /* _UWIN */
  190. #endif /* __DECLSPEC_SUPPORTED */
  191.  
  192. #else /* ! __MSVCRT__ */
  193.  
  194. /* CRTDLL run time library */
  195.  
  196. #ifndef __DECLSPEC_SUPPORTED
  197.   extern int*    _imp___sys_nerr_dll;
  198. # define sys_nerr    (*_imp___sys_nerr_dll)
  199. #else /* __DECLSPEC_SUPPORTED */
  200.   __MINGW_IMPORT int    _sys_nerr_dll;
  201. # define sys_nerr    _sys_nerr_dll
  202. #endif /* __DECLSPEC_SUPPORTED */
  203.  
  204. #endif /* ! __MSVCRT__ */
  205.  
  206. #ifndef __DECLSPEC_SUPPORTED
  207. extern char***    _imp__sys_errlist;
  208. #define    sys_errlist    (*_imp___sys_errlist)
  209. #else /* __DECLSPEC_SUPPORTED */
  210. __MINGW_IMPORT char*    _sys_errlist[];
  211. #ifndef _UWIN
  212. #define    sys_errlist    _sys_errlist
  213. #endif /* _UWIN */
  214. #endif /* __DECLSPEC_SUPPORTED */
  215.  
  216. /*
  217.  * OS version and such constants.
  218.  */
  219. #ifndef __STRICT_ANSI__
  220.  
  221. #ifdef    __MSVCRT__
  222. /* msvcrtxx.dll */
  223.  
  224. extern unsigned int*    __p__osver(void);
  225. extern unsigned int*    __p__winver(void);
  226. extern unsigned int*    __p__winmajor(void);
  227. extern unsigned int*    __p__winminor(void);
  228.  
  229. #ifndef __DECLSPEC_SUPPORTED
  230. # define _osver        (*__p__osver())
  231. # define _winver    (*__p__winver())
  232. # define _winmajor    (*__p__winmajor())
  233. # define _winminor    (*__p__winminor())
  234. #else
  235. __MINGW_IMPORT unsigned int _osver;
  236. __MINGW_IMPORT unsigned int _winver;
  237. __MINGW_IMPORT unsigned int _winmajor;
  238. __MINGW_IMPORT unsigned int _winminor;
  239. #endif /* __DECLSPEC_SUPPORTED */
  240.  
  241. #else
  242. /* Not msvcrtxx.dll, thus crtdll.dll */
  243.  
  244. #ifndef __DECLSPEC_SUPPORTED
  245.  
  246. extern unsigned int*    _imp___osver_dll;
  247. extern unsigned int*    _imp___winver_dll;
  248. extern unsigned int*    _imp___winmajor_dll;
  249. extern unsigned int*    _imp___winminor_dll;
  250.  
  251. #define _osver        (*_imp___osver_dll)
  252. #define _winver        (*_imp___winver_dll)
  253. #define _winmajor    (*_imp___winmajor_dll)
  254. #define _winminor    (*_imp___winminor_dll)
  255.  
  256. #else /* __DECLSPEC_SUPPORTED */
  257.  
  258. __MINGW_IMPORT unsigned int    _osver_dll;
  259. __MINGW_IMPORT unsigned int    _winver_dll;
  260. __MINGW_IMPORT unsigned int    _winmajor_dll;
  261. __MINGW_IMPORT unsigned int    _winminor_dll;
  262.  
  263. #define _osver        _osver_dll
  264. #define _winver        _winver_dll
  265. #define _winmajor    _winmajor_dll
  266. #define _winminor    _winminor_dll
  267.  
  268. #endif /* __DECLSPEC_SUPPORTED */
  269.  
  270. #endif
  271.  
  272. #if defined  __MSVCRT__
  273. /* although the _pgmptr is exported as DATA,
  274.  * be safe and use the access function __p__pgmptr() to get it. */
  275. char**  __p__pgmptr(void);
  276. #define _pgmptr     (*__p__pgmptr())
  277. wchar_t**  __p__wpgmptr(void);
  278. #define _wpgmptr    (*__p__wpgmptr())
  279. #else /* ! __MSVCRT__ */
  280. # ifndef __DECLSPEC_SUPPORTED
  281.   extern char** __imp__pgmptr_dll;
  282. # define _pgmptr (*_imp___pgmptr_dll)
  283. # else /* __DECLSPEC_SUPPORTED */
  284.  __MINGW_IMPORT char* _pgmptr_dll;
  285. # define _pgmptr _pgmptr_dll
  286. # endif /* __DECLSPEC_SUPPORTED */
  287. /* no wide version in CRTDLL */
  288. #endif /* __MSVCRT__ */
  289.  
  290. /*
  291.  * This variable determines the default file mode.
  292.  * TODO: Which flags work?
  293.  */
  294. #if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
  295.  
  296. #ifdef __MSVCRT__
  297. extern int* _imp___fmode;
  298. #define    _fmode    (*_imp___fmode)
  299. #else
  300. /* CRTDLL */
  301. extern int* _imp___fmode_dll;
  302. #define    _fmode    (*_imp___fmode_dll)
  303. #endif
  304.  
  305. #else /* __DECLSPEC_SUPPORTED */
  306.  
  307. #ifdef __MSVCRT__
  308. __MINGW_IMPORT  int _fmode;
  309. #else /* ! __MSVCRT__ */
  310. __MINGW_IMPORT  int _fmode_dll;
  311. #define    _fmode    _fmode_dll
  312. #endif /* ! __MSVCRT__ */
  313.  
  314. #endif /* __DECLSPEC_SUPPORTED */
  315.  
  316. #endif /* Not __STRICT_ANSI__ */
  317.  
  318. #ifdef    __GNUC__
  319. #define    _ATTRIB_NORETURN    __attribute__ ((noreturn))
  320. #else    /* Not __GNUC__ */
  321. #define    _ATTRIB_NORETURN
  322. #endif    /* __GNUC__ */
  323.  
  324. double    atof    (const char*);
  325. int    atoi    (const char*);
  326. long    atol    (const char*);
  327. int    _wtoi (const wchar_t *);
  328. long _wtol (const wchar_t *);
  329.  
  330. double    strtod    (const char*, char**);
  331. #if !defined __NO_ISOCEXT  /* extern stubs in static libmingwex.a */
  332. extern __inline__ float strtof (const char *nptr, char **endptr)
  333.   { return (strtod (nptr, endptr));}
  334. long double strtold (const char * __restrict__, char ** __restrict__);
  335. #endif /* __NO_ISOCEXT */
  336.  
  337. long    strtol    (const char*, char**, int);
  338. unsigned long    strtoul    (const char*, char**, int);
  339.  
  340. #ifndef _WSTDLIB_DEFINED
  341. /*  also declared in wchar.h */
  342. double    wcstod    (const wchar_t*, wchar_t**);
  343. #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
  344. extern __inline__ float wcstof( const wchar_t *nptr, wchar_t **endptr)
  345. {  return (wcstod(nptr, endptr)); }
  346. long double wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__);
  347. #endif /* __NO_ISOCEXT */
  348.  
  349. long    wcstol    (const wchar_t*, wchar_t**, int);
  350. unsigned long    wcstoul (const wchar_t*, wchar_t**, int);
  351. #define _WSTDLIB_DEFINED
  352. #endif
  353.  
  354. size_t    wcstombs    (char*, const wchar_t*, size_t);
  355. int    wctomb        (char*, wchar_t);
  356.  
  357. int    mblen        (const char*, size_t);
  358. size_t    mbstowcs    (wchar_t*, const char*, size_t);
  359. int    mbtowc        (wchar_t*, const char*, size_t);
  360.  
  361. int    rand    (void);
  362. void    srand    (unsigned int);
  363.  
  364. void*    calloc    (size_t, size_t);
  365. void*    malloc    (size_t);
  366. void*    realloc    (void*, size_t);
  367. void    free    (void*);
  368.  
  369. void    abort    (void) _ATTRIB_NORETURN;
  370. void    exit    (int) _ATTRIB_NORETURN;
  371. int    atexit    (void (*)(void));
  372.  
  373. int    system    (const char*);
  374. char*    getenv    (const char*);
  375.  
  376. void*    bsearch    (const void*, const void*, size_t, size_t, 
  377.                  int (*)(const void*, const void*));
  378. void    qsort    (const void*, size_t, size_t,
  379.                  int (*)(const void*, const void*));
  380.  
  381. int    abs    (int);
  382. long    labs    (long);
  383.  
  384. /*
  385.  * div_t and ldiv_t are structures used to return the results of div and
  386.  * ldiv.
  387.  *
  388.  * NOTE: div and ldiv appear not to work correctly unless
  389.  *       -fno-pcc-struct-return is specified. This is included in the
  390.  *       mingw32 specs file.
  391.  */
  392. typedef struct { int quot, rem; } div_t;
  393. typedef struct { long quot, rem; } ldiv_t;
  394.  
  395. div_t    div    (int, int);
  396. ldiv_t    ldiv    (long, long);
  397.  
  398. #ifndef    __STRICT_ANSI__
  399.  
  400. /*
  401.  * NOTE: Officially the three following functions are obsolete. The Win32 API
  402.  *       functions SetErrorMode, Beep and Sleep are their replacements.
  403.  */
  404. void    _beep (unsigned int, unsigned int);
  405. void    _seterrormode (int);
  406. void    _sleep (unsigned long);
  407.  
  408. void    _exit    (int) _ATTRIB_NORETURN;
  409. #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
  410. /* C99 function name */
  411. void _Exit(int) _ATTRIB_NORETURN; /* Declare to get noreturn attribute.  */
  412. extern __inline__ void _Exit(int status)
  413.     {  _exit(status); }
  414. #endif
  415. /* _onexit is MS extension. Use atexit for portability.  */
  416. typedef  int (* _onexit_t)(void);
  417. _onexit_t _onexit( _onexit_t );
  418.  
  419. int    _putenv    (const char*);
  420. void    _searchenv (const char*, const char*, char*);
  421.  
  422.  
  423. char*    _ecvt (double, int, int*, int*);
  424. char*    _fcvt (double, int, int*, int*);
  425. char*    _gcvt (double, int, char*);
  426.  
  427. void    _makepath (char*, const char*, const char*, const char*, const char*);
  428. void    _splitpath (const char*, char*, char*, char*, char*);
  429. char*    _fullpath (char*, const char*, size_t);
  430.  
  431.  
  432. char*    _itoa (int, char*, int);
  433. char*    _ltoa (long, char*, int);
  434. char*   _ultoa(unsigned long, char*, int);
  435. wchar_t*  _itow (int, wchar_t*, int);
  436. wchar_t*  _ltow (long, wchar_t*, int);
  437. wchar_t*  _ultow (unsigned long, wchar_t*, int);
  438.  
  439. #ifdef __MSVCRT__
  440. __int64    _atoi64(const char *);
  441. char*    _i64toa(__int64, char *, int);
  442. char*    _ui64toa(unsigned __int64, char *, int);
  443. __int64    _wtoi64(const wchar_t *);
  444. wchar_t* _i64tow(__int64, wchar_t *, int);
  445. wchar_t* _ui64tow(unsigned __int64, wchar_t *, int);
  446.  
  447. wchar_t* _wgetenv(const wchar_t*);
  448. int     _wputenv(const wchar_t*);
  449. void    _wsearchenv(const wchar_t*, const wchar_t*, wchar_t*);
  450. void    _wmakepath(wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*);
  451. void    _wsplitpath (const wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
  452. wchar_t*    _wfullpath (wchar_t*, const wchar_t*, size_t);
  453.  
  454. unsigned int _rotl(unsigned int, int);
  455. unsigned int _rotr(unsigned int, int);
  456. unsigned long _lrotl(unsigned long, int);
  457. unsigned long _lrotr(unsigned long, int);
  458. #endif
  459.  
  460. #ifndef    _NO_OLDNAMES
  461.  
  462. int    putenv (const char*);
  463. void    searchenv (const char*, const char*, char*);
  464.  
  465. char*    itoa (int, char*, int);
  466. char*    ltoa (long, char*, int);
  467.  
  468. #ifndef _UWIN
  469. char*    ecvt (double, int, int*, int*);
  470. char*    fcvt (double, int, int*, int*);
  471. char*    gcvt (double, int, char*);
  472. #endif /* _UWIN */
  473. #endif    /* Not _NO_OLDNAMES */
  474.  
  475. #endif    /* Not __STRICT_ANSI__ */
  476.  
  477. /* C99 names */
  478.  
  479. #if !defined __NO_ISOCEXT /* externs in static libmingwex.a */
  480.  
  481. typedef struct { long long quot, rem; } lldiv_t;
  482.  
  483. lldiv_t    lldiv (long long, long long);
  484.  
  485. extern __inline__ long long llabs(long long _j)
  486.   {return (_j >= 0 ? _j : -_j);}
  487.  
  488. long long strtoll (const char* __restrict__, char** __restrict, int);
  489. unsigned long long strtoull (const char* __restrict__, char** __restrict__, int);
  490.  
  491. #if defined (__MSVCRT__) /* these are stubs for MS _i64 versions */ 
  492. long long atoll (const char *);
  493.  
  494. #if !defined (__STRICT_ANSI__)
  495. long long wtoll(const wchar_t *);
  496. char* lltoa(long long, char *, int);
  497. char* ulltoa(unsigned long long , char *, int);
  498. wchar_t* lltow(long long, wchar_t *, int);
  499. wchar_t* ulltow(unsigned long long, wchar_t *, int);
  500.  
  501.   /* inline using non-ansi functions */
  502. extern __inline__ long long atoll (const char * _c)
  503.     { return _atoi64 (_c); }
  504. extern __inline__ char* lltoa(long long _n, char * _c, int _i)
  505.     { return _i64toa (_n, _c, _i); }
  506. extern __inline__ char* ulltoa(unsigned long long _n, char * _c, int _i)
  507.     { return _ui64toa (_n, _c, _i); }
  508. extern __inline__ long long wtoll(const wchar_t * _w)
  509.      { return _wtoi64 (_w); }
  510. extern __inline__ wchar_t* lltow(long long _n, wchar_t * _w, int _i)
  511.     { return _i64tow (_n, _w, _i); } 
  512. extern __inline__ wchar_t* ulltow(unsigned long long _n, wchar_t * _w, int _i)
  513.     { return _ui64tow (_n, _w, _i); } 
  514. #endif /* (__STRICT_ANSI__)  */
  515.  
  516. #endif /* __MSVCRT__ */
  517.  
  518. #endif /* !__NO_ISOCEXT */
  519.  
  520. /*
  521.  * Undefine the no return attribute used in some function definitions
  522.  */
  523. #undef    _ATTRIB_NORETURN
  524.  
  525. #ifdef __cplusplus
  526. }
  527. #endif
  528.  
  529. #endif    /* Not RC_INVOKED */
  530.  
  531. #endif    /* Not _STDLIB_H_ */
  532.  
  533.