• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
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_FXCRT_FX_SYSTEM_H_
8 #define CORE_FXCRT_FX_SYSTEM_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <wchar.h>
15 
16 #include "build/build_config.h"
17 #include "core/fxcrt/compiler_specific.h"
18 #include "core/fxcrt/fx_types.h"
19 
20 #if defined(_MSC_VER) && _MSC_VER < 1900
21 #error Sorry, VC++ 2015 or later is required to compile PDFium.
22 #endif  // defined(_MSC_VER) && _MSC_VER < 1900
23 
24 #if defined(__wasm__) && defined(PDF_ENABLE_V8)
25 #error Cannot compile v8 with wasm.
26 #endif  // PDF_ENABLE_V8
27 
28 #if BUILDFLAG(IS_WIN)
29 #include <windows.h>
30 #endif  // BUILDFLAG(IS_WIN)
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif  // __cplusplus
35 
36 #define FXSYS_IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
37 #define FXSYS_IsFloatBigger(fa, fb) \
38   ((fa) > (fb) && !FXSYS_IsFloatZero((fa) - (fb)))
39 #define FXSYS_IsFloatSmaller(fa, fb) \
40   ((fa) < (fb) && !FXSYS_IsFloatZero((fa) - (fb)))
41 #define FXSYS_IsFloatEqual(fa, fb) FXSYS_IsFloatZero((fa) - (fb))
42 
43 // M_PI not universally present on all platforms.
44 #define FXSYS_PI 3.1415926535897932384626433832795f
45 #define FXSYS_BEZIER 0.5522847498308f
46 
47 // NOTE: prevent use of the return value from snprintf() since some platforms
48 // have different return values.
49 #define FXSYS_snprintf (void)snprintf
50 #define FXSYS_vsnprintf (void)vsnprintf
51 #define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE
52 #define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE
53 
54 #if BUILDFLAG(IS_WIN)
55 #define FXSYS_itoa _itoa
56 #define FXSYS_strlwr _strlwr
57 #define FXSYS_strupr _strupr
58 #define FXSYS_wcslwr _wcslwr
59 #define FXSYS_wcsupr _wcsupr
60 #define FXSYS_SetLastError SetLastError
61 #define FXSYS_GetLastError GetLastError
62 UNSAFE_BUFFER_USAGE size_t FXSYS_wcsftime(wchar_t* strDest,
63                                           size_t maxsize,
64                                           const wchar_t* format,
65                                           const struct tm* timeptr);
66 #else  // BUILDFLAG(IS_WIN)
67 char* FXSYS_itoa(int value, char* str, int radix);
68 char* FXSYS_strlwr(char* str);
69 char* FXSYS_strupr(char* str);
70 wchar_t* FXSYS_wcslwr(wchar_t* str);
71 wchar_t* FXSYS_wcsupr(wchar_t* str);
72 void FXSYS_SetLastError(uint32_t err);
73 uint32_t FXSYS_GetLastError();
74 #define FXSYS_wcsftime wcsftime
75 #endif  // BUILDFLAG(IS_WIN)
76 
77 const char* FXSYS_i64toa(int64_t value, char* str, int radix);
78 int FXSYS_roundf(float f);
79 int FXSYS_round(double d);
80 float FXSYS_sqrt2(float a, float b);
81 
82 #ifdef __cplusplus
83 }  // extern "C"
84 
85 // C++-only section to allow future use of TerminatedPtr<>.
86 int FXSYS_stricmp(const char* str1, const char* str2);
87 int FXSYS_wcsicmp(const wchar_t* str1, const wchar_t* str2);
88 int32_t FXSYS_atoi(const char* str);
89 int32_t FXSYS_wtoi(const wchar_t* str);
90 uint32_t FXSYS_atoui(const char* str);
91 int64_t FXSYS_atoi64(const char* str);
92 
93 #endif  // __cplusplus
94 
95 #endif  // CORE_FXCRT_FX_SYSTEM_H_
96