Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: core/include/fxcrt/fx_system.h

Issue 1825953002: Move core/include/fxcrt to core/fxcrt/include. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/include/fxcrt/fx_ucd.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef CORE_INCLUDE_FXCRT_FX_SYSTEM_H_
8 #define CORE_INCLUDE_FXCRT_FX_SYSTEM_H_
9
10 #include <assert.h>
11 #include <math.h>
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <wchar.h>
19
20 // _FX_OS_ values:
21 #define _FX_WIN32_DESKTOP_ 1
22 #define _FX_WIN64_DESKTOP_ 2
23 #define _FX_LINUX_DESKTOP_ 4
24 #define _FX_MACOSX_ 7
25 #define _FX_ANDROID_ 12
26
27 // _FXM_PLATFORM_ values;
28 #define _FXM_PLATFORM_WINDOWS_ 1 // _FX_WIN32_DESKTOP_ or _FX_WIN64_DESKTOP_.
29 #define _FXM_PLATFORM_LINUX_ 2 // _FX_LINUX_DESKTOP_ always.
30 #define _FXM_PLATFORM_APPLE_ 3 // _FX_MACOSX_ always.
31 #define _FXM_PLATFORM_ANDROID_ 4 // _FX_ANDROID_ always.
32
33 #ifndef _FX_OS_
34 #if defined(__ANDROID__)
35 #define _FX_OS_ _FX_ANDROID_
36 #define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
37 #elif defined(_WIN32)
38 #define _FX_OS_ _FX_WIN32_DESKTOP_
39 #define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
40 #elif defined(_WIN64)
41 #define _FX_OS_ _FX_WIN64_DESKTOP_
42 #define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
43 #elif defined(__linux__)
44 #define _FX_OS_ _FX_LINUX_DESKTOP_
45 #define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
46 #elif defined(__APPLE__)
47 #define _FX_OS_ _FX_MACOSX_
48 #define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
49 #endif
50 #endif // _FX_OS_
51
52 #if !defined(_FX_OS_) || _FX_OS_ == 0
53 #error Sorry, can not figure out target OS. Please specify _FX_OS_ macro.
54 #endif
55
56 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
57 #define _CRT_SECURE_NO_WARNINGS
58 #include <windows.h>
59 #include <sal.h>
60 #endif
61
62 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
63 #include <Carbon/Carbon.h>
64 #include <libkern/OSAtomic.h>
65 #endif
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 typedef void* FX_POSITION; // Keep until fxcrt containers gone
71 typedef uint32_t FX_DWORD; // Keep - "an efficient type"
72 typedef float FX_FLOAT; // Keep, allow upgrade to doubles.
73 typedef double FX_DOUBLE; // Keep, allow downgrade to floats.
74 typedef int FX_BOOL; // Keep, sadly not always 0 or 1.
75 typedef char FX_CHAR; // Keep, questionable signedness.
76 typedef wchar_t FX_WCHAR; // Keep, maybe bad platform wchars.
77
78 // PDFium string sizes are limited to 2^31-1, and the value is signed to
79 // allow -1 as a placeholder for "unknown".
80 // TODO(palmer): it should be a |size_t|, or at least unsigned.
81 typedef int FX_STRSIZE;
82
83 #ifndef TRUE
84 #define TRUE 1
85 #endif
86
87 #ifndef FALSE
88 #define FALSE 0
89 #endif
90
91 #ifdef __cplusplus
92 static_assert(TRUE == true, "true_needs_to_be_true");
93 static_assert(FALSE == false, "false_needs_to_be_false");
94 #endif
95
96 #ifndef NULL
97 #define NULL 0
98 #endif
99
100 #define FXSYS_assert assert
101 #ifndef ASSERT
102 #ifndef NDEBUG
103 #define ASSERT FXSYS_assert
104 #else
105 #define ASSERT(a)
106 #endif
107 #endif
108
109 // M_PI not universally present on all platforms.
110 #define FX_PI 3.1415926535897932384626433832795f
111 #define FX_BEZIER 0.5522847498308f
112
113 // NOTE: prevent use of the return value from snprintf() since some platforms
114 // have different return values (e.g. windows _vsnprintf()), and provide
115 // versions that always NUL-terminate.
116 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900
117 void FXSYS_snprintf(char* str,
118 size_t size,
119 _Printf_format_string_ const char* fmt,
120 ...);
121 void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap);
122 #else
123 #define FXSYS_snprintf (void) snprintf
124 #define FXSYS_vsnprintf (void) vsnprintf
125 #endif
126
127 #define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE
128 #define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE
129 #define FXSYS_strchr strchr
130 #define FXSYS_strncmp strncmp
131 #define FXSYS_strcmp strcmp
132 #define FXSYS_strcpy strcpy
133 #define FXSYS_strncpy strncpy
134 #define FXSYS_strstr strstr
135 #define FXSYS_FILE FILE
136 #define FXSYS_fopen fopen
137 #define FXSYS_fclose fclose
138 #define FXSYS_SEEK_END SEEK_END
139 #define FXSYS_SEEK_SET SEEK_SET
140 #define FXSYS_fseek fseek
141 #define FXSYS_ftell ftell
142 #define FXSYS_fread fread
143 #define FXSYS_fwrite fwrite
144 #define FXSYS_fprintf fprintf
145 #define FXSYS_fflush fflush
146
147 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
148 #ifdef _NATIVE_WCHAR_T_DEFINED
149 #define FXSYS_wfopen(f, m) _wfopen((const wchar_t*)(f), (const wchar_t*)(m))
150 #else
151 #define FXSYS_wfopen _wfopen
152 #endif
153 #else
154 FXSYS_FILE* FXSYS_wfopen(const FX_WCHAR* filename, const FX_WCHAR* mode);
155 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
156
157 #ifdef __cplusplus
158 } // extern "C"
159
160 #include "third_party/base/numerics/safe_conversions.h"
161
162 #define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr))
163 #define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr))
164
165 extern "C" {
166 #else
167 #define FXSYS_strlen(ptr) ((FX_STRSIZE)strlen(ptr))
168 #define FXSYS_wcslen(ptr) ((FX_STRSIZE)wcslen(ptr))
169 #endif
170
171 #define FXSYS_wcscmp wcscmp
172 #define FXSYS_wcschr wcschr
173 #define FXSYS_wcsstr wcsstr
174 #define FXSYS_wcsncmp wcsncmp
175 #define FXSYS_vswprintf vswprintf
176 #define FXSYS_mbstowcs mbstowcs
177 #define FXSYS_wcstombs wcstombs
178 #define FXSYS_memcmp memcmp
179 #define FXSYS_memcpy memcpy
180 #define FXSYS_memmove memmove
181 #define FXSYS_memset memset
182 #define FXSYS_memchr memchr
183 #define FXSYS_qsort qsort
184 #define FXSYS_bsearch bsearch
185
186 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
187 #define FXSYS_GetACP GetACP
188 #define FXSYS_itoa _itoa
189 #define FXSYS_strlwr _strlwr
190 #define FXSYS_strupr _strupr
191 #define FXSYS_stricmp _stricmp
192 #ifdef _NATIVE_WCHAR_T_DEFINED
193 #define FXSYS_wcsicmp(str1, str2) _wcsicmp((wchar_t*)(str1), (wchar_t*)(str2))
194 #define FXSYS_WideCharToMultiByte(p1, p2, p3, p4, p5, p6, p7, p8) \
195 WideCharToMultiByte(p1, p2, (const wchar_t*)(p3), p4, p5, p6, p7, p8)
196 #define FXSYS_MultiByteToWideChar(p1, p2, p3, p4, p5, p6) \
197 MultiByteToWideChar(p1, p2, p3, p4, (wchar_t*)(p5), p6)
198 #define FXSYS_wcslwr(str) _wcslwr((wchar_t*)(str))
199 #define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str))
200 #else
201 #define FXSYS_wcsicmp _wcsicmp
202 #define FXSYS_WideCharToMultiByte WideCharToMultiByte
203 #define FXSYS_MultiByteToWideChar MultiByteToWideChar
204 #define FXSYS_wcslwr _wcslwr
205 #define FXSYS_wcsupr _wcsupr
206 #endif
207 #define FXSYS_GetFullPathName GetFullPathName
208 #define FXSYS_GetModuleFileName GetModuleFileName
209 #else
210 int FXSYS_GetACP(void);
211 char* FXSYS_itoa(int value, char* str, int radix);
212 int FXSYS_WideCharToMultiByte(FX_DWORD codepage,
213 FX_DWORD dwFlags,
214 const wchar_t* wstr,
215 int wlen,
216 char* buf,
217 int buflen,
218 const char* default_str,
219 int* pUseDefault);
220 int FXSYS_MultiByteToWideChar(FX_DWORD codepage,
221 FX_DWORD dwFlags,
222 const char* bstr,
223 int blen,
224 wchar_t* buf,
225 int buflen);
226 FX_DWORD FXSYS_GetFullPathName(const char* filename,
227 FX_DWORD buflen,
228 char* buf,
229 char** filepart);
230 FX_DWORD FXSYS_GetModuleFileName(void* hModule, char* buf, FX_DWORD bufsize);
231 char* FXSYS_strlwr(char* str);
232 char* FXSYS_strupr(char* str);
233 int FXSYS_stricmp(const char*, const char*);
234 int FXSYS_wcsicmp(const wchar_t* str1, const wchar_t* str2);
235 wchar_t* FXSYS_wcslwr(wchar_t* str);
236 wchar_t* FXSYS_wcsupr(wchar_t* str);
237 #endif // _FXM_PLATFORM == _FXM_PLATFORM_WINDOWS_
238
239 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
240 #define FXSYS_pow(a, b) (FX_FLOAT) powf(a, b)
241 #else
242 #define FXSYS_pow(a, b) (FX_FLOAT) pow(a, b)
243 #endif
244 #define FXSYS_sqrt(a) (FX_FLOAT) sqrt(a)
245 #define FXSYS_fabs(a) (FX_FLOAT) fabs(a)
246 #define FXSYS_atan2(a, b) (FX_FLOAT) atan2(a, b)
247 #define FXSYS_ceil(a) (FX_FLOAT) ceil(a)
248 #define FXSYS_floor(a) (FX_FLOAT) floor(a)
249 #define FXSYS_cos(a) (FX_FLOAT) cos(a)
250 #define FXSYS_acos(a) (FX_FLOAT) acos(a)
251 #define FXSYS_sin(a) (FX_FLOAT) sin(a)
252 #define FXSYS_log(a) (FX_FLOAT) log(a)
253 #define FXSYS_log10(a) (FX_FLOAT) log10(a)
254 #define FXSYS_fmod(a, b) (FX_FLOAT) fmod(a, b)
255 #define FXSYS_abs abs
256 #define FXDWORD_FROM_LSBFIRST(i) (i)
257 #define FXDWORD_FROM_MSBFIRST(i) \
258 (((uint8_t)(i) << 24) | ((uint8_t)((i) >> 8) << 16) | \
259 ((uint8_t)((i) >> 16) << 8) | (uint8_t)((i) >> 24))
260 #define FXDWORD_GET_LSBFIRST(p) \
261 ((static_cast<FX_DWORD>(p[3]) << 24) | (static_cast<FX_DWORD>(p[2]) << 16) | \
262 (static_cast<FX_DWORD>(p[1]) << 8) | (static_cast<FX_DWORD>(p[0])))
263 #define FXDWORD_GET_MSBFIRST(p) \
264 ((static_cast<FX_DWORD>(p[0]) << 24) | (static_cast<FX_DWORD>(p[1]) << 16) | \
265 (static_cast<FX_DWORD>(p[2]) << 8) | (static_cast<FX_DWORD>(p[3])))
266 #define FXSYS_HIBYTE(word) ((uint8_t)((word) >> 8))
267 #define FXSYS_LOBYTE(word) ((uint8_t)(word))
268 #define FXSYS_HIWORD(dword) ((uint16_t)((dword) >> 16))
269 #define FXSYS_LOWORD(dword) ((uint16_t)(dword))
270 int32_t FXSYS_atoi(const FX_CHAR* str);
271 uint32_t FXSYS_atoui(const FX_CHAR* str);
272 int32_t FXSYS_wtoi(const FX_WCHAR* str);
273 int64_t FXSYS_atoi64(const FX_CHAR* str);
274 int64_t FXSYS_wtoi64(const FX_WCHAR* str);
275 const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix);
276 int FXSYS_round(FX_FLOAT f);
277 #define FXSYS_sqrt2(a, b) (FX_FLOAT) FXSYS_sqrt((a) * (a) + (b) * (b))
278 #ifdef __cplusplus
279 };
280 #endif
281
282 // To print a size_t value in a portable way:
283 // size_t size;
284 // printf("xyz: %" PRIuS, size);
285 // The "u" in the macro corresponds to %u, and S is for "size".
286
287 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
288
289 #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
290 #error "inttypes.h has already been included before this header file, but "
291 #error "without __STDC_FORMAT_MACROS defined."
292 #endif
293
294 #if !defined(__STDC_FORMAT_MACROS)
295 #define __STDC_FORMAT_MACROS
296 #endif
297
298 #include <inttypes.h>
299
300 #if !defined(PRIuS)
301 #define PRIuS "zu"
302 #endif
303
304 #else // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
305
306 #if !defined(PRIuS)
307 #define PRIuS "Iu"
308 #endif
309
310 #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
311
312 // Prevent a function from ever being inlined, typically because we'd
313 // like it to appear in stack traces.
314 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
315 #define NEVER_INLINE __declspec(noinline)
316 #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
317 #define NEVER_INLINE __attribute__((__noinline__))
318 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
319
320 #endif // CORE_INCLUDE_FXCRT_FX_SYSTEM_H_
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/include/fxcrt/fx_ucd.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698