os.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #ifndef _RAR_OS_
  2. #define _RAR_OS_
  3. #define FALSE 0
  4. #define TRUE 1
  5. #ifdef __EMX__
  6. #define INCL_BASE
  7. #endif
  8. #if defined(RARDLL) && !defined(SILENT)
  9. #define SILENT
  10. #endif
  11. #include <new>
  12. #if defined(_WIN_ALL) || defined(_EMX)
  13. #define LITTLE_ENDIAN
  14. #define NM 2048
  15. #ifdef _WIN_ALL
  16. // We got a report that just "#define STRICT" is incompatible with
  17. // "#define STRICT 1" in Windows 10 SDK minwindef.h and depending on the order
  18. // in which these statements are reached this may cause a compiler warning
  19. // and build break for other projects incorporating this source.
  20. // So we changed it to "#define STRICT 1".
  21. #ifndef STRICT
  22. #define STRICT 1
  23. #endif
  24. // 'ifndef' check here is needed for unrar.dll header to avoid macro
  25. // re-definition warnings in third party projects.
  26. #ifndef UNICODE
  27. #define UNICODE
  28. #define _UNICODE // Set _T() macro to convert from narrow to wide strings.
  29. #endif
  30. #if 0 // OPENMPT ADDITION
  31. #define WINVER _WIN32_WINNT_WINXP
  32. #endif // OPENMPT ADDITION
  33. #if 0 // OPENMPT ADDITION
  34. #define _WIN32_WINNT _WIN32_WINNT_WINXP
  35. #endif // OPENMPT ADDITION
  36. #if !defined(ZIPSFX)
  37. #define RAR_SMP
  38. #endif
  39. #define WIN32_LEAN_AND_MEAN
  40. #include <windows.h>
  41. #include <prsht.h>
  42. #include <shlwapi.h>
  43. #pragma comment(lib, "Shlwapi.lib")
  44. #include <PowrProf.h>
  45. #pragma comment(lib, "PowrProf.lib")
  46. #include <shellapi.h>
  47. #include <shlobj.h>
  48. #include <winioctl.h>
  49. #include <wincrypt.h>
  50. #include <wchar.h>
  51. #include <wctype.h>
  52. #endif // _WIN_ALL
  53. #include <sys/types.h>
  54. #include <sys/stat.h>
  55. #include <dos.h>
  56. #if !defined(_EMX) && !defined(_MSC_VER)
  57. #include <dir.h>
  58. #endif
  59. #ifdef _MSC_VER
  60. #if _MSC_VER<1500
  61. #define for if (0) ; else for
  62. #endif
  63. #include <direct.h>
  64. #include <intrin.h>
  65. #if !defined(__clang__) // OPENMPT ADDITION
  66. // Use SSE only for x86/x64, not ARM Windows.
  67. #if defined(_M_IX86) || defined(_M_X64)
  68. #define USE_SSE
  69. #define SSE_ALIGNMENT 16
  70. #endif
  71. #endif // OPENMPT ADDITION
  72. #else
  73. #include <dirent.h>
  74. #endif // _MSC_VER
  75. #include <stdio.h>
  76. #include <stdlib.h>
  77. #include <stdarg.h>
  78. #include <string.h>
  79. #include <ctype.h>
  80. #include <fcntl.h>
  81. #include <dos.h>
  82. #include <io.h>
  83. #include <time.h>
  84. #include <signal.h>
  85. #define SAVE_LINKS
  86. #define ENABLE_ACCESS
  87. #define DefConfigName L"rar.ini"
  88. #define DefLogName L"rar.log"
  89. #define SPATHDIVIDER L"\\"
  90. #define CPATHDIVIDER '\\'
  91. #define MASKALL L"*"
  92. #define READBINARY "rb"
  93. #define READTEXT "rt"
  94. #define UPDATEBINARY "r+b"
  95. #define CREATEBINARY "w+b"
  96. #define WRITEBINARY "wb"
  97. #define APPENDTEXT "at"
  98. #if defined(_WIN_ALL)
  99. #ifdef _MSC_VER
  100. #define _stdfunction __cdecl
  101. #define _forceinline __forceinline
  102. #else
  103. #define _stdfunction _USERENTRY
  104. #define _forceinline inline
  105. #endif
  106. #else
  107. #define _stdfunction
  108. #define _forceinline inline
  109. #endif
  110. #endif // defined(_WIN_ALL) || defined(_EMX)
  111. #ifdef _UNIX
  112. #define NM 2048
  113. #include <unistd.h>
  114. #include <sys/types.h>
  115. #include <sys/stat.h>
  116. #include <sys/file.h>
  117. #if defined(__QNXNTO__)
  118. #include <sys/param.h>
  119. #endif
  120. #if defined(RAR_SMP) && defined(__APPLE__)
  121. #include <sys/sysctl.h>
  122. #endif
  123. #ifndef SFX_MODULE
  124. #include <sys/statvfs.h>
  125. #endif
  126. #include <pwd.h>
  127. #include <grp.h>
  128. #include <wchar.h>
  129. #include <wctype.h>
  130. #include <stdio.h>
  131. #include <stdlib.h>
  132. #include <stdarg.h>
  133. #include <string.h>
  134. #include <ctype.h>
  135. #include <fcntl.h>
  136. #include <errno.h>
  137. #include <dirent.h>
  138. #include <time.h>
  139. #include <signal.h>
  140. #include <utime.h>
  141. #include <locale.h>
  142. #ifdef S_IFLNK
  143. #define SAVE_LINKS
  144. #endif
  145. #if defined(__linux) || defined(__FreeBSD__)
  146. #include <sys/time.h>
  147. #define USE_LUTIMES
  148. #endif
  149. #define ENABLE_ACCESS
  150. #define DefConfigName L".rarrc"
  151. #define DefLogName L".rarlog"
  152. #define SPATHDIVIDER L"/"
  153. #define CPATHDIVIDER '/'
  154. #define MASKALL L"*"
  155. #define READBINARY "r"
  156. #define READTEXT "r"
  157. #define UPDATEBINARY "r+"
  158. #define CREATEBINARY "w+"
  159. #define WRITEBINARY "w"
  160. #define APPENDTEXT "a"
  161. #define _stdfunction
  162. #define _forceinline inline
  163. #ifdef _APPLE
  164. #if defined(__BIG_ENDIAN__) && !defined(BIG_ENDIAN)
  165. #define BIG_ENDIAN
  166. #undef LITTLE_ENDIAN
  167. #endif
  168. #if defined(__i386__) && !defined(LITTLE_ENDIAN)
  169. #define LITTLE_ENDIAN
  170. #undef BIG_ENDIAN
  171. #endif
  172. #endif
  173. #if defined(__sparc) || defined(sparc) || defined(__hpux)
  174. #ifndef BIG_ENDIAN
  175. #define BIG_ENDIAN
  176. #endif
  177. #endif
  178. // Unlike Apple x64, utimensat shall be available in all Apple M1 systems.
  179. #if _POSIX_C_SOURCE >= 200809L || defined(__APPLE__) && defined(__arm64__)
  180. #define UNIX_TIME_NS // Nanosecond time precision in Unix.
  181. #endif
  182. #endif // _UNIX
  183. #if 0
  184. #define MSGID_INT
  185. typedef int MSGID;
  186. #else
  187. typedef const wchar* MSGID;
  188. #endif
  189. #ifndef SSE_ALIGNMENT // No SSE use and no special data alignment is required.
  190. #define SSE_ALIGNMENT 1
  191. #endif
  192. #define safebuf static
  193. // Solaris defines _LITTLE_ENDIAN or _BIG_ENDIAN.
  194. #if defined(_LITTLE_ENDIAN) && !defined(LITTLE_ENDIAN)
  195. #define LITTLE_ENDIAN
  196. #endif
  197. #if defined(_BIG_ENDIAN) && !defined(BIG_ENDIAN)
  198. #define BIG_ENDIAN
  199. #endif
  200. #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
  201. #if defined(__i386) || defined(i386) || defined(__i386__) || defined(__x86_64)
  202. #define LITTLE_ENDIAN
  203. #elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__)
  204. #define LITTLE_ENDIAN
  205. #elif defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN || defined(__BIG_ENDIAN__)
  206. #define BIG_ENDIAN
  207. #else
  208. #error "Neither LITTLE_ENDIAN nor BIG_ENDIAN are defined. Define one of them."
  209. #endif
  210. #endif
  211. #if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
  212. #if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
  213. #undef LITTLE_ENDIAN
  214. #elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
  215. #undef BIG_ENDIAN
  216. #else
  217. #error "Both LITTLE_ENDIAN and BIG_ENDIAN are defined. Undef one of them."
  218. #endif
  219. #endif
  220. #if !defined(BIG_ENDIAN) && defined(_WIN_ALL) || defined(__i386__) || defined(__x86_64__)
  221. // Allow not aligned integer access, increases speed in some operations.
  222. #define ALLOW_MISALIGNED
  223. #endif
  224. #endif // _RAR_OS_