blob: 55e15c82192efb9988136feda342ecc314118e6f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- cstdlib ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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 Hinnant324bb032010-08-22 00:02:43 +000024
Howard Hinnantbc8d3f92010-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 Hinnant324bb032010-08-22 00:02:43 +000069lldiv_t div(long long numer, long long denom); // C++0X
Howard Hinnantbc8d3f92010-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);
Howard Hinnant999fc972012-10-13 18:03:53 +000077int at_quick_exit(void (*func)(void)) // C++11
78void quick_exit(int status); // C++11
79void *aligned_alloc(size_t alignment, size_t size); // C11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080
81} // std
82
83*/
84
85#include <__config>
86#include <stdlib.h>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070087#ifdef _LIBCPP_MSVCRT
88#include "support/win32/locale_win32.h"
89#endif // _LIBCPP_MSVCRT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090
Howard Hinnant08e17472011-10-17 20:05:10 +000091#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000093#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094
95_LIBCPP_BEGIN_NAMESPACE_STD
96
97using ::size_t;
98using ::div_t;
99using ::ldiv_t;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000100#ifndef _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101using ::lldiv_t;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000102#endif // _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000103using ::atof;
104using ::atoi;
105using ::atol;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000106#ifndef _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000107using ::atoll;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000108#endif // _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109using ::strtod;
110using ::strtof;
111using ::strtold;
112using ::strtol;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000113#ifndef _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114using ::strtoll;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000115#endif // _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116using ::strtoul;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000117#ifndef _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118using ::strtoull;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000119#endif // _LIBCPP_HAS_NO_LONG_LONG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120using ::rand;
121using ::srand;
122using ::calloc;
123using ::free;
124using ::malloc;
125using ::realloc;
126using ::abort;
127using ::atexit;
128using ::exit;
129using ::_Exit;
130using ::getenv;
131using ::system;
132using ::bsearch;
133using ::qsort;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700134#undef abs
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000135using ::abs;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700136#undef labs
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137using ::labs;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000138#ifndef _LIBCPP_HAS_NO_LONG_LONG
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700139#undef llabs
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140using ::llabs;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000141#endif // _LIBCPP_HAS_NO_LONG_LONG
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700142#undef div
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143using ::div;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700144#undef ldiv
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145using ::ldiv;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000146#ifndef _LIBCPP_HAS_NO_LONG_LONG
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700147#undef lldiv
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148using ::lldiv;
Howard Hinnant8a9c5ea2012-11-26 21:18:17 +0000149#endif // _LIBCPP_HAS_NO_LONG_LONG
Ed Schouten323ade32015-06-24 08:44:38 +0000150#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151using ::mblen;
152using ::mbtowc;
153using ::wctomb;
Ed Schouten323ade32015-06-24 08:44:38 +0000154#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155using ::mbstowcs;
156using ::wcstombs;
David Chisnallf2533a82012-03-14 14:10:37 +0000157#ifdef _LIBCPP_HAS_QUICK_EXIT
158using ::at_quick_exit;
159using ::quick_exit;
160#endif
Howard Hinnant999fc972012-10-13 18:03:53 +0000161#ifdef _LIBCPP_HAS_C11_FEATURES
162using ::aligned_alloc;
163#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700165// MSVCRT already has the correct prototype in <stdlib.h> #ifdef __cplusplus
166#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
167inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
168#ifndef _LIBCPP_HAS_NO_LONG_LONG
169inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
170#endif // _LIBCPP_HAS_NO_LONG_LONG
171
172inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
173#ifndef _LIBCPP_HAS_NO_LONG_LONG
174inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
175#endif // _LIBCPP_HAS_NO_LONG_LONG
176#endif // _LIBCPP_MSVCRT
177
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178_LIBCPP_END_NAMESPACE_STD
179
180#endif // _LIBCPP_CSTDLIB