blob: bf8e85e7bdb1203275ea263866ec5d7e7422fd90 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- cstdlib ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_CSTDLIB
12#define _LIBCPP_CSTDLIB
13
14/*
15 cstdlib synopsis
16
17Macros:
18
19 EXIT_FAILURE
20 EXIT_SUCCESS
21 MB_CUR_MAX
22 NULL
23 RAND_MAX
Howard Hinnant3b6579a2010-08-22 00:02:43 +000024
Howard Hinnantc51e1022010-05-11 19:42:16 +000025namespace std
26{
27
28Types:
29
30 size_t
31 div_t
32 ldiv_t
33 lldiv_t // C99
34
35double atof (const char* nptr);
36int atoi (const char* nptr);
37long atol (const char* nptr);
38long long atoll(const char* nptr); // C99
39double strtod (const char* restrict nptr, char** restrict endptr);
40float strtof (const char* restrict nptr, char** restrict endptr); // C99
41long double strtold (const char* restrict nptr, char** restrict endptr); // C99
42long strtol (const char* restrict nptr, char** restrict endptr, int base);
43long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
44unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);
45unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
46int rand(void);
47void srand(unsigned int seed);
48void* calloc(size_t nmemb, size_t size);
49void free(void* ptr);
50void* malloc(size_t size);
51void* realloc(void* ptr, size_t size);
52void abort(void);
53int atexit(void (*func)(void));
54void exit(int status);
55void _Exit(int status);
56char* getenv(const char* name);
57int system(const char* string);
58void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
59 int (*compar)(const void *, const void *));
60void qsort(void* base, size_t nmemb, size_t size,
61 int (*compar)(const void *, const void *));
62int abs( int j);
63long abs( long j);
64long long abs(long long j); // C++0X
65long labs( long j);
66long long llabs(long long j); // C99
67div_t div( int numer, int denom);
68ldiv_t div( long numer, long denom);
Howard Hinnant3b6579a2010-08-22 00:02:43 +000069lldiv_t div(long long numer, long long denom); // C++0X
Howard Hinnantc51e1022010-05-11 19:42:16 +000070ldiv_t ldiv( long numer, long denom);
71lldiv_t lldiv(long long numer, long long denom); // C99
72int mblen(const char* s, size_t n);
73int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
74int wctomb(char* s, wchar_t wchar);
75size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
76size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
77
78} // std
79
80*/
81
82#include <__config>
83#include <stdlib.h>
Howard Hinnantbf074022011-10-22 20:59:45 +000084#ifdef _MSC_VER
Howard Hinnant69d80702011-10-27 16:24:42 +000085#include "support/win32/locale_win32.h"
Howard Hinnantbf074022011-10-22 20:59:45 +000086#endif // _MSC_VER
Howard Hinnantc51e1022010-05-11 19:42:16 +000087
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000088#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000089#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000090#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000091
92_LIBCPP_BEGIN_NAMESPACE_STD
93
94using ::size_t;
95using ::div_t;
96using ::ldiv_t;
97using ::lldiv_t;
98using ::atof;
99using ::atoi;
100using ::atol;
101using ::atoll;
102using ::strtod;
103using ::strtof;
104using ::strtold;
105using ::strtol;
106using ::strtoll;
107using ::strtoul;
108using ::strtoull;
109using ::rand;
110using ::srand;
111using ::calloc;
112using ::free;
113using ::malloc;
114using ::realloc;
115using ::abort;
116using ::atexit;
117using ::exit;
118using ::_Exit;
119using ::getenv;
120using ::system;
121using ::bsearch;
122using ::qsort;
123using ::abs;
124using ::labs;
125using ::llabs;
126using ::div;
127using ::ldiv;
128using ::lldiv;
129using ::mblen;
130using ::mbtowc;
131using ::wctomb;
132using ::mbstowcs;
133using ::wcstombs;
David Chisnall277ad052012-03-14 14:10:37 +0000134#ifdef _LIBCPP_HAS_QUICK_EXIT
135using ::at_quick_exit;
136using ::quick_exit;
137#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138
David Chisnall8074c342012-02-29 13:05:08 +0000139// MSVC already has the correct prototype in <stdlib.h.h> #ifdef __cplusplus
140#if !defined(_MSC_VER) && !defined(__sun__)
Howard Hinnant68ba1fb2012-07-06 19:16:56 +0000141inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
142inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Howard Hinnant68ba1fb2012-07-06 19:16:56 +0000144inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
145inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
Howard Hinnantbf074022011-10-22 20:59:45 +0000146#endif // _MSC_VER
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
148_LIBCPP_END_NAMESPACE_STD
149
150#endif // _LIBCPP_CSTDLIB