ucommon
cpr.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU uCommon C++.
4 //
5 // GNU uCommon C++ is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU uCommon C++ is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17 
25 #ifndef _UCOMMON_CONFIG_H_
26 #include <ucommon/platform.h>
27 #endif
28 
29 #ifndef _UCOMMON_CPR_H_
30 #define _UCOMMON_CPR_H_
31 
32 #ifdef _MSWINDOWS_
33 
34 extern "C" {
35  __EXPORT int cpr_setenv(const char *s, const char *v, int p);
36 
37  inline int setenv(const char *s, const char *v, int overwrite)
38  {return cpr_setenv(s, v, overwrite);}
39 }
40 
41 #endif
42 
43 
50 __EXPORT void cpr_runtime_error(const char *text);
51 
58 extern "C" __EXPORT void *cpr_memalloc(size_t size) __MALLOC;
59 
69 extern "C" __EXPORT void *cpr_memassign(size_t size, caddr_t address, size_t known) __MALLOC;
70 
77 extern "C" __EXPORT void cpr_memswap(void *mem1, void *mem2, size_t size);
78 
79 #ifndef _UCOMMON_EXTENDED_
80 
85 inline void *operator new(size_t size)
86  {return cpr_memalloc(size);}
87 
93 inline void *operator new[](size_t size)
94  {return cpr_memalloc(size);}
95 #endif
96 
97 #ifndef _UCOMMON_EXTENDED_
98 
106 inline void *operator new[](size_t size, caddr_t address)
107  {return cpr_memassign(size, address, size);}
108 
118 inline void *operator new[](size_t size, caddr_t address, size_t known)
119  {return cpr_memassign(size, address, known);}
120 #endif
121 
131 inline void *operator new(size_t size, size_t extra)
132  {return cpr_memalloc(size + extra);}
133 
142 inline void *operator new(size_t size, caddr_t address)
143  {return cpr_memassign(size, address, size);}
144 
155 inline void *operator new(size_t size, caddr_t address, size_t known)
156  {return cpr_memassign(size, address, known);}
157 
158 #ifndef _UCOMMON_EXTENDED_
159 
163 inline void operator delete(void *object)
164  {free(object);}
165 
170 inline void operator delete[](void *array)
171  {free(array);}
172 
173 #ifdef __GNUC__
174 extern "C" __EXPORT void __cxa_pure_virtual(void);
175 #endif
176 #endif
177 
178 extern "C" {
179  __EXPORT uint16_t lsb_getshort(uint8_t *b);
180  __EXPORT uint32_t lsb_getlong(uint8_t *b);
181  __EXPORT uint16_t msb_getshort(uint8_t *b);
182  __EXPORT uint32_t msb_getlong(uint8_t *b);
183 
184  __EXPORT void lsb_setshort(uint8_t *b, uint16_t v);
185  __EXPORT void lsb_setlong(uint8_t *b, uint32_t v);
186  __EXPORT void msb_setshort(uint8_t *b, uint16_t v);
187  __EXPORT void msb_setlong(uint8_t *b, uint32_t v);
188 }
189 
190 #endif
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
void * cpr_memassign(size_t size, caddr_t address, size_t known)
Portable memory placement helper function.
void * cpr_memalloc(size_t size)
Portable memory allocation helper function.
Various miscellaneous platform specific headers and defines.
void cpr_runtime_error(const char *text)
Function to handle runtime errors.