AndroidSpecific.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : Specific to Android declarations, inline functions etc.
  9. #ifndef CRYINCLUDE_CRYCOMMON_ANDROIDSPECIFIC_H
  10. #define CRYINCLUDE_CRYCOMMON_ANDROIDSPECIFIC_H
  11. #pragma once
  12. #if defined(__arm__) || defined(__aarch64__)
  13. #define _CPU_ARM
  14. #endif
  15. #if defined(__aarch64__)
  16. #define PLATFORM_64BIT
  17. #endif
  18. #if defined(__ARM_NEON__) || defined(__ARM_NEON)
  19. #define _CPU_NEON
  20. #endif
  21. #ifndef MOBILE
  22. #define MOBILE
  23. #endif
  24. //////////////////////////////////////////////////////////////////////////
  25. // Standard includes.
  26. //////////////////////////////////////////////////////////////////////////
  27. #include <malloc.h>
  28. #include <stdint.h>
  29. #include <fcntl.h>
  30. #include <float.h>
  31. #include <sys/types.h>
  32. #include <dirent.h>
  33. #include <sys/stat.h>
  34. #include <time.h>
  35. #include <ctype.h>
  36. #include <sys/socket.h>
  37. #include <errno.h>
  38. //////////////////////////////////////////////////////////////////////////
  39. //////////////////////////////////////////////////////////////////////////
  40. // Define platform independent types.
  41. //////////////////////////////////////////////////////////////////////////
  42. #include "BaseTypes.h"
  43. typedef signed long long INT64;
  44. typedef double real;
  45. typedef uint32 DWORD;
  46. typedef DWORD* LPDWORD;
  47. #if defined(PLATFORM_64BIT)
  48. typedef uint64 DWORD_PTR;
  49. #else
  50. typedef DWORD DWORD_PTR;
  51. #endif
  52. typedef intptr_t INT_PTR, *PINT_PTR;
  53. typedef uintptr_t UINT_PTR, * PUINT_PTR;
  54. typedef char* LPSTR, * PSTR;
  55. typedef uint64 __uint64;
  56. typedef int64 INT64;
  57. typedef uint64 UINT64;
  58. typedef long LONG_PTR, * PLONG_PTR, * PLONG;
  59. typedef unsigned long ULONG_PTR, * PULONG_PTR;
  60. typedef unsigned char BYTE;
  61. typedef unsigned short WORD;
  62. typedef void* HWND;
  63. typedef UINT_PTR WPARAM;
  64. typedef LONG_PTR LPARAM;
  65. typedef LONG_PTR LRESULT;
  66. #define PLARGE_INTEGER LARGE_INTEGER *
  67. typedef const char* LPCSTR, * PCSTR;
  68. typedef long long LONGLONG;
  69. typedef ULONG_PTR SIZE_T;
  70. typedef unsigned char byte;
  71. #define ILINE __forceinline
  72. #define _A_RDONLY (0x01)
  73. #define _A_SUBDIR (0x10)
  74. //////////////////////////////////////////////////////////////////////////
  75. // Win32 FileAttributes.
  76. //////////////////////////////////////////////////////////////////////////
  77. #define FILE_ATTRIBUTE_READONLY 0x00000001
  78. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  79. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  80. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  81. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  82. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  83. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  84. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  85. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  86. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  87. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  88. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  89. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  90. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  91. #define INVALID_FILE_ATTRIBUTES (-1)
  92. #include "LinuxSpecific.h"
  93. // these functions do not exist int the wchar.h header
  94. #undef wscasecomp
  95. #undef wscasencomp
  96. extern int wcsicmp (const wchar_t* s1, const wchar_t* s2);
  97. extern int wcsnicmp (const wchar_t* s1, const wchar_t* s2, size_t count);
  98. // these are not defined in android-19 and prior
  99. #undef wcsnlen
  100. extern size_t wcsnlen(const wchar_t* str, size_t maxLen);
  101. #undef stpcpy
  102. extern char* stpcpy(char* dest, const char* str);
  103. // end android-19
  104. #define TARGET_DEFAULT_ALIGN (16U)
  105. #ifdef _RELEASE
  106. #define __debugbreak()
  107. #else
  108. #define __debugbreak() __builtin_trap()
  109. #endif
  110. // there is no __finite in android, only variants of isfinite
  111. #undef __finite
  112. #if NDK_REV_MAJOR >= 16
  113. #define __finite isfinite
  114. #else
  115. #define __finite __isfinite
  116. #endif
  117. #define S_IWRITE S_IWUSR
  118. #define ILINE __forceinline
  119. #define _A_RDONLY (0x01)
  120. #define _A_SUBDIR (0x10)
  121. #define _A_HIDDEN (0x02)
  122. #include <android/api-level.h>
  123. #if __ANDROID_API__ == 19
  124. // The following were apparently introduced in API 21, however in earlier versions of the
  125. // platform specific headers they were defines. In the move to unified headers, the follwoing
  126. // defines were removed from stat.h
  127. #ifndef stat64
  128. #define stat64 stat
  129. #endif
  130. #ifndef fstat64
  131. #define fstat64 fstat
  132. #endif
  133. #ifndef lstat64
  134. #define lstat64 lstat
  135. #endif
  136. #endif // __ANDROID_API__ == 19
  137. // std::stoull deosn't exist on android, so we need to define it
  138. namespace std
  139. {
  140. inline unsigned long long stoull(const std::string& str, size_t* idx = 0, int base = 10)
  141. {
  142. const char* start = str.c_str();
  143. char* end = nullptr;
  144. unsigned long long result = strtoull(start, &end, base);
  145. if (idx)
  146. {
  147. *idx = end - start;
  148. }
  149. return result;
  150. }
  151. }
  152. #endif // CRYINCLUDE_CRYCOMMON_ANDROIDSPECIFIC_H