VirtualBox

source: vbox/trunk/include/iprt/nocrt/stdlib.h@ 96060

Last change on this file since 96060 was 96017, checked in by vboxsync, 3 years ago

include/iprt/nocrt: Header build fixes for windows. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.6 KB
Line 
1/** @file
2 * IPRT / No-CRT - Our minimal stdlib.h.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.215389.xyz. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_nocrt_stdlib_h
27#define IPRT_INCLUDED_nocrt_stdlib_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/assert.h>
33#include <iprt/env.h>
34#include <iprt/mem.h>
35#include <iprt/nocrt/limits.h>
36
37RT_C_DECLS_BEGIN
38
39#define EXIT_SUCCESS RTEXITCODE_SUCCESS
40#define EXIT_FAILURE RTEXITCODE_FAILURE
41
42
43typedef void FNRTNOCRTATEXITCALLBACK(void) /*RT_NOEXCEPT*/;
44typedef FNRTNOCRTATEXITCALLBACK *PFNRTNOCRTATEXITCALLBACK;
45#if defined(_MSC_VER) && defined(RT_WITHOUT_NOCRT_WRAPPERS) /* Clashes with compiler internal prototype or smth. */
46int rtnocrt_atexit(PFNRTNOCRTATEXITCALLBACK) RT_NOEXCEPT;
47# define atexit rtnocrt_atexit
48#else
49int RT_NOCRT(atexit)(PFNRTNOCRTATEXITCALLBACK) RT_NOEXCEPT;
50#endif
51
52#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES)
53# define atexit RT_NOCRT(atexit)
54#endif
55
56
57#ifdef IPRT_NO_CRT_FOR_3RD_PARTY
58/*
59 * Only for external libraries and such.
60 */
61
62DECLINLINE(void *) RT_NOCRT(malloc)(size_t cb)
63{
64 return RTMemAlloc(cb);
65}
66
67DECLINLINE(void *) RT_NOCRT(calloc)(size_t cItems, size_t cbItem)
68{
69 return RTMemAllocZ(cItems * cbItem); /* caller responsible for overflow issues. */
70}
71
72DECLINLINE(void *) RT_NOCRT(realloc)(void *pvOld, size_t cbNew)
73{
74 return RTMemRealloc(pvOld, cbNew);
75}
76
77DECLINLINE(void) RT_NOCRT(free)(void *pv)
78{
79 RTMemFree(pv);
80}
81
82DECLINLINE(const char *) RT_NOCRT(getenv)(const char *pszVar)
83{
84 return RTEnvGet(pszVar);
85}
86
87int RT_NOCRT(abs)(int);
88long RT_NOCRT(labs)(long);
89long RT_NOCRT(labs)(long);
90long long RT_NOCRT(llabs)(long long);
91int RT_NOCRT(rand)(void);
92void RT_NOCRT(srand)(unsigned);
93long RT_NOCRT(strtol)(const char *psz, char **ppszNext, int iBase);
94long long RT_NOCRT(strtoll)(const char *psz, char **ppszNext, int iBase);
95unsigned long RT_NOCRT(strtoul)(const char *psz, char **ppszNext, int iBase);
96unsigned long long RT_NOCRT(strtoull)(const char *psz, char **ppszNext, int iBase);
97int RT_NOCRT(atoi)(const char *psz);
98double RT_NOCRT(strtod)(const char *psz, char **ppszNext);
99double RT_NOCRT(atof)(const char *psz);
100void *RT_NOCRT(bsearch)(const void *pvKey, const void *pvBase, size_t cEntries, size_t cbEntry,
101 int (*pfnCompare)(const void *pv1, const void *pv2));
102void RT_NOCRT(qsort)(void *pvBase, size_t cEntries, size_t cbEntry,
103 int (*pfnCompare)(const void *pv1, const void *pv2));
104void RT_NOCRT(qsort_r)(void *pvBase, size_t cEntries, size_t cbEntry,
105 int (*pfnCompare)(const void *pv1, const void *pv2, void *pvUser), void *pvUser);
106
107/* Map exit & abort onto fatal assert. */
108DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(exit)(int iExitCode) { AssertMsgFailed(("exit: iExitCode=%d\n", iExitCode)); }
109DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(abort)(void) { AssertMsgFailed(("abort\n")); }
110
111/*
112 * Underscored versions:
113 */
114DECLINLINE(void *) RT_NOCRT(_malloc)(size_t cb)
115{
116 return RTMemAlloc(cb);
117}
118
119DECLINLINE(void *) RT_NOCRT(_calloc)(size_t cItems, size_t cbItem)
120{
121 return RTMemAllocZ(cItems * cbItem); /* caller responsible for overflow issues. */
122}
123
124DECLINLINE(void *) RT_NOCRT(_realloc)(void *pvOld, size_t cbNew)
125{
126 return RTMemRealloc(pvOld, cbNew);
127}
128
129DECLINLINE(void) RT_NOCRT(_free)(void *pv)
130{
131 RTMemFree(pv);
132}
133
134DECLINLINE(const char *) RT_NOCRT(_getenv)(const char *pszVar)
135{
136 return RTEnvGet(pszVar);
137}
138
139int RT_NOCRT(_abs)(int);
140long RT_NOCRT(_labs)(long);
141long RT_NOCRT(_labs)(long);
142long long RT_NOCRT(_llabs)(long long);
143int RT_NOCRT(_rand)(void);
144void RT_NOCRT(_srand)(unsigned);
145long RT_NOCRT(_strtol)(const char *psz, char **ppszNext, int iBase);
146long long RT_NOCRT(_strtoll)(const char *psz, char **ppszNext, int iBase);
147unsigned long RT_NOCRT(_strtoul)(const char *psz, char **ppszNext, int iBase);
148unsigned long long RT_NOCRT(_strtoull)(const char *psz, char **ppszNext, int iBase);
149int RT_NOCRT(_atoi)(const char *psz);
150double RT_NOCRT(_strtod)(const char *psz, char **ppszNext);
151double RT_NOCRT(_atof)(const char *psz);
152void *RT_NOCRT(_bsearch)(const void *pvKey, const void *pvBase, size_t cEntries, size_t cbEntry,
153 int (*pfnCompare)(const void *pv1, const void *pv2));
154void RT_NOCRT(_qsort)(void *pvBase, size_t cEntries, size_t cbEntry,
155 int (*pfnCompare)(const void *pv1, const void *pv2));
156void RT_NOCRT(_qsort_r)(void *pvBase, size_t cEntries, size_t cbEntry,
157 int (*pfnCompare)(const void *pv1, const void *pv2, void *pvUser), void *pvUser);
158
159/* Map exit & abort onto fatal assert. */
160DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(_exit)(int iExitCode) { AssertMsgFailed(("_exit: iExitCode=%d\n", iExitCode)); }
161DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(_abort)(void) { AssertMsgFailed(("_abort\n")); }
162
163/* Some windows CRT error control functions we totally ignore (only underscored): */
164# define _set_error_mode(a_Mode) (0)
165# define _set_abort_behavior(a_fFlags, a_fMask) (0)
166
167/*
168 * No-CRT aliases.
169 */
170# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES)
171# define malloc RT_NOCRT(malloc)
172# define calloc RT_NOCRT(calloc)
173# define realloc RT_NOCRT(realloc)
174# define free RT_NOCRT(free)
175# define getenv RT_NOCRT(getenv)
176# define bsearch RT_NOCRT(bsearch)
177# define exit RT_NOCRT(exit)
178# define abort RT_NOCRT(abort)
179# define rand RT_NOCRT(rand)
180# define srand RT_NOCRT(srand)
181# define strtol RT_NOCRT(strtol)
182# define strtoll RT_NOCRT(strtoll)
183# define strtoul RT_NOCRT(strtoul)
184# define strtoull RT_NOCRT(strtoull)
185# define atoi RT_NOCRT(atoi)
186# define strtod RT_NOCRT(strtod)
187# define atof RT_NOCRT(atof)
188
189# define _malloc RT_NOCRT(malloc)
190# define _calloc RT_NOCRT(calloc)
191# define _realloc RT_NOCRT(realloc)
192# define _free RT_NOCRT(free)
193# define _getenv RT_NOCRT(getenv)
194# define _bsearch RT_NOCRT(bsearch)
195# define _exit RT_NOCRT(exit)
196# define _abort RT_NOCRT(abort)
197# define _strtol RT_NOCRT(strtol)
198# define _strtoll RT_NOCRT(strtoll)
199# define _strtoul RT_NOCRT(strtoul)
200# define _strtoull RT_NOCRT(strtoull)
201# define _atoi RT_NOCRT(atoi)
202# define _strtod RT_NOCRT(strtod)
203# define _atof RT_NOCRT(atof)
204# endif
205
206#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */
207
208
209RT_C_DECLS_END
210
211#endif /* !IPRT_INCLUDED_nocrt_stdlib_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette