1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved.
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Use of this source code is governed by a BSD-style license that can be
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// found in the LICENSE file.
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_SYSTEM_H_
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_SYSTEM_H_
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_WIN32_DESKTOP_		1
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_LINUX_DESKTOP_		4
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_MACOSX_				7
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_ANDROID_			12
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_WINDOWS_		1
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_LINUX_		2
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_APPLE_		3
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_ANDROID_		4
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_OS_
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if defined(__ANDROID__)
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_OS_ _FX_ANDROID_
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#elif defined(_WIN32) || defined(_WIN64)
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_OS_ _FX_WIN32_DESKTOP_
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#elif defined(__linux__)
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_OS_ _FX_LINUX_DESKTOP_
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#elif defined(__APPLE__)
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_OS_ _FX_MACOSX_
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if !defined(_FX_OS_) || _FX_OS_ == 0
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#error Sorry, can not figure out what OS you are targeting to. Please specify _FX_OS_ macro.
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _CRT_SECURE_NO_WARNINGS
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <windows.h>
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_W32_		1
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_W64_		2
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_WORDSIZE_
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if defined(_WIN64) || defined(__arm64) || defined(__arm64__) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(__powerpc64__) || defined(__x86_64__) || __WORDSIZE == 64 || defined(__LP64__)
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_WORDSIZE_	_FX_W64_
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_WORDSIZE_	_FX_W32_
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <stddef.h>
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <stdarg.h>
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <setjmp.h>
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <stdlib.h>
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <stdio.h>
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <string.h>
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <assert.h>
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <wchar.h>
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <libkern/OSAtomic.h>
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FX_OS_ == _FX_MACOSX_
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <Carbon/Carbon.h>
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#elif _FX_OS_ == _FX_IOS_
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <CoreText/CoreText.h>
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <CoreGraphics/CoreGraphics.h>
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef __cplusplus
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovextern "C" {
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef void*					FX_LPVOID;
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef void const*				FX_LPCVOID;
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef void*					FX_POSITION;
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef signed char				FX_INT8;
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned char			FX_UINT8;
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned char			FX_BYTE;
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned char*			FX_LPBYTE;
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned char const*	FX_LPCBYTE;
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef short					FX_INT16;
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned short			FX_UINT16;
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef short					FX_SHORT;
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned short			FX_WORD;
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned short*			FX_LPWORD;
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned short const*	FX_LPCWORD;
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef int						FX_INT32;
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef float					FX_FLOAT;
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef int						FX_BOOL;
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef int						FX_ERR;
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_SUCCEEDED(Status)	((FX_ERR)(Status) >= 0)
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_FAILED(Status)		((FX_ERR)(Status) < 0)
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef char					FX_CHAR;
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef char*					FX_LPSTR;
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef char const*				FX_LPCSTR;
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned int		FX_DWORD;
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned int*		FX_LPDWORD;
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef __int64				FX_INT64;
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned __int64	FX_UINT64;
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef long long int		FX_INT64;
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned long long	FX_UINT64;
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FX_WORDSIZE_ == _FX_W64_
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef FX_INT64			FX_INTPTR;
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef FX_UINT64			FX_UINTPTR;
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef int					FX_INTPTR;
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef unsigned int		FX_UINTPTR;
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef wchar_t					FX_WCHAR;
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef wchar_t*				FX_LPWSTR;
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef wchar_t const*			FX_LPCWSTR;
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef FX_DWORD				FX_UINT32;
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef FX_UINT64				FX_QWORD;
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_DEFINEHANDLE(name)	typedef struct _##name {FX_LPVOID pData;} * name;
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if defined(DEBUG) && !defined(_DEBUG)
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _DEBUG
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef TRUE
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define TRUE	1
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef FALSE
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FALSE	0
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef NULL
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define NULL	0
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_assert assert
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef ASSERT
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _DEBUG
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define ASSERT FXSYS_assert
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define ASSERT(a)
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_MAX(a, b) (((a) > (b)) ? (a) : (b))
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_MIN(a, b) (((a) < (b)) ? (a) : (b))
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FX_PI	3.1415926535897932384626433832795f
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_snprintf	_snprintf
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_snprintf	snprintf
144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
145ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_sprintf	sprintf
146ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_vsprintf	vsprintf
147ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strchr	strchr
148ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strlen	strlen
149ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strncmp	strncmp
150ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strcmp	strcmp
151ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strcpy	strcpy
152ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strncpy	strncpy
153ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strstr	strstr
154ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_FILE		FILE
155ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fopen		fopen
156ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fclose	fclose
157ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_SEEK_END	SEEK_END
158ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_SEEK_SET	SEEK_SET
159ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fseek		fseek
160ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_ftell		ftell
161ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fread		fread
162ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fwrite	fwrite
163ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fprintf	fprintf
164ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fflush	fflush
165ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
166ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _NATIVE_WCHAR_T_DEFINED
167ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wfopen(f, m) _wfopen((const wchar_t*)(f), (const wchar_t*)(m))
168ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
169ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wfopen _wfopen
170ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
171ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
172ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode);
173ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
174ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
175ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcslen	wcslen
176ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcscmp	wcscmp
177ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcschr	wcschr
178ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsstr	wcsstr
179ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsncmp	wcsncmp
180ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_vswprintf	vswprintf
181ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_mbstowcs	mbstowcs
182ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcstombs	wcstombs
183ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memcmp	memcmp
184ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memcpy	memcpy
185ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memmove	memmove
186ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memset	memset
187ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memchr	memchr
188ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_qsort		qsort
189ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_bsearch	bsearch
190ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
191ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_GetACP GetACP
192ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_itoa _itoa
193ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strlwr _strlwr
194ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_strupr _strupr
195ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_stricmp _stricmp
196ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _NATIVE_WCHAR_T_DEFINED
197ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsicmp(str1, str2) _wcsicmp((wchar_t*)(str1), (wchar_t*)(str2))
198ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_WideCharToMultiByte(p1, p2, p3, p4, p5, p6, p7, p8) WideCharToMultiByte(p1, p2, (const wchar_t*)(p3), p4, p5, p6, p7, p8)
199ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_MultiByteToWideChar(p1, p2, p3, p4, p5, p6) MultiByteToWideChar(p1, p2, p3, p4, (wchar_t*)(p5), p6)
200ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcslwr(str) _wcslwr((wchar_t*)(str))
201ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str))
202ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
203ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsicmp _wcsicmp
204ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_WideCharToMultiByte WideCharToMultiByte
205ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_MultiByteToWideChar MultiByteToWideChar
206ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcslwr _wcslwr
207ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_wcsupr _wcsupr
208ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
209ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_GetFullPathName GetFullPathName
210ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_GetModuleFileName GetModuleFileName
211ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
212ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_GetACP(void);
213ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovchar*		FXSYS_itoa(int value, char* string, int radix);
214ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_WideCharToMultiByte(FX_DWORD codepage, FX_DWORD dwFlags, const wchar_t* wstr, int wlen,
215ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                      char* buf, int buflen, const char* default_str, int* pUseDefault);
216ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_MultiByteToWideChar(FX_DWORD codepage, FX_DWORD dwFlags, const char* bstr, int blen,
217ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                      wchar_t* buf, int buflen);
218ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_DWORD	FXSYS_GetFullPathName(const char* filename, FX_DWORD buflen, char* buf, char** filepart);
219ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_DWORD	FXSYS_GetModuleFileName(void* hModule, char* buf, FX_DWORD bufsize);
220ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovchar*		FXSYS_strlwr(char* str);
221ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovchar*		FXSYS_strupr(char* str);
222ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_stricmp(const char*, const char*);
223ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_wcsicmp(const wchar_t *string1, const wchar_t *string2);
224ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovwchar_t*	FXSYS_wcslwr(wchar_t* str);
225ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovwchar_t*	FXSYS_wcsupr(wchar_t* str);
226ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
227ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memcpy32		FXSYS_memcpy
228ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memcmp32		FXSYS_memcmp
229ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memset32		FXSYS_memset
230ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memset8		FXSYS_memset
231ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_memmove32		FXSYS_memmove
232ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef __cplusplus
233ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
234ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
235ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include <math.h>
236ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
237ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_pow(a, b)		(FX_FLOAT)powf(a, b)
238ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
239ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_pow(a, b)		(FX_FLOAT)pow(a, b)
240ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
241ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_sqrt(a)		(FX_FLOAT)sqrt(a)
242ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fabs(a)		(FX_FLOAT)fabs(a)
243ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_atan2(a, b)	(FX_FLOAT)atan2(a, b)
244ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_ceil(a)		(FX_FLOAT)ceil(a)
245ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_floor(a)		(FX_FLOAT)floor(a)
246ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_cos(a)		(FX_FLOAT)cos(a)
247ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_acos(a)		(FX_FLOAT)acos(a)
248ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_sin(a)		(FX_FLOAT)sin(a)
249ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_log(a)		(FX_FLOAT)log(a)
250ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_log10(a)		(FX_FLOAT)log10(a)
251ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_fmod(a, b)	(FX_FLOAT)fmod(a, b)
252ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_abs			abs
253ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef __cplusplus
254ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovextern "C" {
255ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
256ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_LSB_FIRST_
257ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXDWORD_FROM_LSBFIRST(i)	(i)
258ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXDWORD_FROM_MSBFIRST(i)	(((FX_BYTE)(i) << 24) | ((FX_BYTE)((i) >> 8) << 16) | ((FX_BYTE)((i) >> 16) << 8) | (FX_BYTE)((i) >> 24))
259ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXDWORD_GET_LSBFIRST(p)		((((FX_LPBYTE)(p))[3] << 24) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0]))
260ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXDWORD_GET_MSBFIRST(p) ((((FX_LPBYTE)(p))[0] << 24) | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | (((FX_LPBYTE)(p))[3]))
261ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_HIBYTE(word)	((FX_BYTE)((word) >> 8))
262ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_LOBYTE(word)	((FX_BYTE)(word))
263ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_HIWORD(dword)	((FX_WORD)((dword) >> 16))
264ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define FXSYS_LOWORD(dword)	((FX_WORD)(dword))
265ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_INT32	FXSYS_atoi(FX_LPCSTR str);
266ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_INT32	FXSYS_wtoi(FX_LPCWSTR str);
267ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_INT64	FXSYS_atoi64(FX_LPCSTR str);
268ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_INT64	FXSYS_wtoi64(FX_LPCWSTR str);
269ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_LPCSTR	FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix);
270ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_LPCWSTR	FXSYS_i64tow(FX_INT64 value, FX_LPWSTR str, int radix);
271ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint			FXSYS_round(FX_FLOAT f);
272ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define		FXSYS_Mul(a, b) ((a) * (b))
273ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define		FXSYS_Div(a, b) ((a) / (b))
274ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define		FXSYS_MulDiv(a, b, c) ((a) * (b) / (c))
275ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define		FXSYS_sqrt2(a, b) (FX_FLOAT)FXSYS_sqrt((a)*(a) + (b)*(b))
276ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef __cplusplus
277ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
278ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
279ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
280