UCommon
cpr.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
26 #ifndef _UCOMMON_CONFIG_H_
27 #include <ucommon/platform.h>
28 #endif
29 
30 #ifndef _UCOMMON_CPR_H_
31 #define _UCOMMON_CPR_H_
32 
33 #ifdef _MSWINDOWS_
34 
35 extern "C" {
36  __EXPORT int setenv(const char *s, const char *v, int p);
37 
38  __EXPORT int gettimeofday(struct timeval *tv, void *tz);
39 }
40 
41 #else
42 #include <unistd.h>
43 #endif
44 
45 
52 __EXPORT void cpr_runtime_error(const char *text);
53 
54 extern "C" __EXPORT void *cpr_newp(void **handle, size_t size);
55 
56 extern "C" __EXPORT void cpr_freep(void **handle);
57 
64 extern "C" __EXPORT void *cpr_memalloc(size_t size) __MALLOC;
65 
75 extern "C" __EXPORT void *cpr_memassign(size_t size, caddr_t address, size_t known) __MALLOC;
76 
83 extern "C" __EXPORT void cpr_memswap(void *mem1, void *mem2, size_t size);
84 
85 #ifdef UCOMMON_SYSRUNTIME
86 
91 __EXPORT void *operator new(size_t size);
92 
98 __EXPORT void *operator new[](size_t size);
99 
108 __EXPORT void *operator new[](size_t size, void *address);
109 
119 __EXPORT void *operator new[](size_t size, void *address, size_t known);
120 
125 #if __cplusplus <= 199711L
126 __EXPORT void operator delete(void *object);
127 #else
128 __EXPORT void operator delete(void *object) noexcept (true);
129 #endif
130 
135 #if __cplusplus <= 199711L
136 __EXPORT void operator delete[](void *array);
137 #else
138 __EXPORT void operator delete[](void *array) noexcept(true);
139 #endif
140 
141 #ifdef __GNUC__
142 extern "C" __EXPORT void __cxa_pure_virtual(void);
143 #endif
144 #endif
145 
146 extern "C" {
147 #if !defined(_MSWINDOWS_) && !defined(__QNX__)
148  __EXPORT int stricmp(const char *s1, const char *s2);
149  __EXPORT int strnicmp(const char *s1, const char *s2, size_t size);
150 
151 #elif defined(_MSWINDOWS_)
152  inline char *strdup(const char *s)
153  {return _strdup(s);}
154 
155  inline int stricmp(const char *s1, const char *s2)
156  {return _stricmp(s1, s2);}
157 
158  inline int strnicmp(const char *s1, const char *s2, size_t size)
159  {return _strnicmp(s1, s2, size);}
160 #endif
161 
162  __EXPORT uint16_t lsb_getshort(uint8_t *b);
163  __EXPORT uint32_t lsb_getlong(uint8_t *b);
164  __EXPORT uint16_t msb_getshort(uint8_t *b);
165  __EXPORT uint32_t msb_getlong(uint8_t *b);
166 
167  __EXPORT void lsb_setshort(uint8_t *b, uint16_t v);
168  __EXPORT void lsb_setlong(uint8_t *b, uint32_t v);
169  __EXPORT void msb_setshort(uint8_t *b, uint16_t v);
170  __EXPORT void msb_setlong(uint8_t *b, uint32_t v);
171 
172  __EXPORT long tzoffset(struct timezone *tz = NULL);
173 }
174 
175 template <typename T>
176 T *newp(T **handle) {
177  return static_cast<T*>(cpr_newp(handle, sizeof(T)));
178 }
179 
180 template <typename T>
181 void freep(T **handle) {
182  cpr_freep(handle);
183 }
184 
185 #endif
void * cpr_memassign(size_t size, caddr_t address, size_t known)
Portable memory placement helper function.
void cpr_runtime_error(const char *text)
Function to handle runtime errors.
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
Various miscellaneous platform specific headers and defines.
void * cpr_memalloc(size_t size)
Portable memory allocation helper function.