xsum_config.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * xxhsum - Command line interface for xxhash algorithms
  3. * Copyright (C) 2013-2020 Yann Collet
  4. *
  5. * GPL v2 License
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * You can contact the author at:
  22. * - xxHash homepage: https://www.xxhash.com
  23. * - xxHash source repository: https://github.com/Cyan4973/xxHash
  24. */
  25. /*
  26. * This contains various configuration parameters and feature detection for
  27. * xxhsum.
  28. *
  29. * Similar to config.h in Autotools, this should be the first header included.
  30. */
  31. #ifndef XSUM_CONFIG_H
  32. #define XSUM_CONFIG_H
  33. /* ************************************
  34. * Compiler Options
  35. **************************************/
  36. /*
  37. * Disable Visual C's warnings when using the "insecure" CRT functions instead
  38. * of the "secure" _s functions.
  39. *
  40. * These functions are not portable, and aren't necessary if you are using the
  41. * original functions properly.
  42. */
  43. #if defined(_MSC_VER) || defined(_WIN32)
  44. # ifndef _CRT_SECURE_NO_WARNINGS
  45. # define _CRT_SECURE_NO_WARNINGS
  46. # endif
  47. #endif
  48. /* Under Linux at least, pull in the *64 commands */
  49. #ifndef _LARGEFILE64_SOURCE
  50. # define _LARGEFILE64_SOURCE
  51. #endif
  52. #ifndef _FILE_OFFSET_BITS
  53. # define _FILE_OFFSET_BITS 64
  54. #endif
  55. /*
  56. * So we can use __attribute__((__format__))
  57. */
  58. #ifdef __GNUC__
  59. # define XSUM_ATTRIBUTE(x) __attribute__(x)
  60. #else
  61. # define XSUM_ATTRIBUTE(x)
  62. #endif
  63. #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) /* UNIX-like OS */ \
  64. || defined(__midipix__) || defined(__VMS))
  65. # if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1-2001 (SUSv3) conformant */ \
  66. || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* BSD distros */
  67. # define XSUM_PLATFORM_POSIX_VERSION 200112L
  68. # else
  69. # if defined(__linux__) || defined(__linux)
  70. # ifndef _POSIX_C_SOURCE
  71. # define _POSIX_C_SOURCE 200112L /* use feature test macro */
  72. # endif
  73. # endif
  74. # include <unistd.h> /* declares _POSIX_VERSION */
  75. # if defined(_POSIX_VERSION) /* POSIX compliant */
  76. # define XSUM_PLATFORM_POSIX_VERSION _POSIX_VERSION
  77. # else
  78. # define XSUM_PLATFORM_POSIX_VERSION 0
  79. # endif
  80. # endif
  81. #endif
  82. #if !defined(XSUM_PLATFORM_POSIX_VERSION)
  83. # define XSUM_PLATFORM_POSIX_VERSION -1
  84. #endif
  85. #if !defined(S_ISREG)
  86. # define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
  87. #endif
  88. /* ************************************
  89. * Windows helpers
  90. **************************************/
  91. /*
  92. * Whether to use the Windows UTF-16 APIs instead of the portable libc 8-bit
  93. * ("ANSI") APIs.
  94. *
  95. * Windows is not UTF-8 clean by default, and the only way to access every file
  96. * on the OS is to use UTF-16.
  97. *
  98. * Do note that xxhsum uses UTF-8 internally and only uses UTF-16 for command
  99. * line arguments, console I/O, and opening files.
  100. *
  101. * Additionally, this guarantees all piped output is UTF-8.
  102. */
  103. #if defined(XSUM_WIN32_USE_WCHAR) && !defined(_WIN32)
  104. /* We use Windows APIs, only use this on Windows. */
  105. # undef XSUM_WIN32_USE_WCHAR
  106. #endif
  107. #ifndef XSUM_WIN32_USE_WCHAR
  108. # if defined(_WIN32)
  109. # include <wchar.h>
  110. # if WCHAR_MAX == 0xFFFFU /* UTF-16 wchar_t */
  111. # define XSUM_WIN32_USE_WCHAR 1
  112. # else
  113. # define XSUM_WIN32_USE_WCHAR 0
  114. # endif
  115. # else
  116. # define XSUM_WIN32_USE_WCHAR 0
  117. # endif
  118. #endif
  119. #if !XSUM_WIN32_USE_WCHAR
  120. /*
  121. * It doesn't make sense to have one without the other.
  122. * Due to XSUM_WIN32_USE_WCHAR being undef'd, this also handles
  123. * non-WIN32 platforms.
  124. */
  125. # undef XSUM_WIN32_USE_WMAIN
  126. # define XSUM_WIN32_USE_WMAIN 0
  127. #else
  128. /*
  129. * Whether to use wmain() or main().
  130. *
  131. * wmain() is preferred because we don't have to mess with internal hidden
  132. * APIs.
  133. *
  134. * It always works on MSVC, but in MinGW, it only works on MinGW-w64 with the
  135. * -municode flag.
  136. *
  137. * Therefore we have to use main() -- there is no better option.
  138. */
  139. # ifndef XSUM_WIN32_USE_WMAIN
  140. # if defined(_UNICODE) || defined(UNICODE) /* MinGW -municode */ \
  141. || defined(_MSC_VER) /* MSVC */
  142. # define XSUM_WIN32_USE_WMAIN 1
  143. # else
  144. # define XSUM_WIN32_USE_WMAIN 0
  145. # endif
  146. # endif
  147. /*
  148. * It is always good practice to define these to prevent accidental use of the
  149. * ANSI APIs, even if the program primarily uses UTF-8.
  150. */
  151. # ifndef _UNICODE
  152. # define _UNICODE
  153. # endif
  154. # ifndef UNICODE
  155. # define UNICODE
  156. # endif
  157. #endif /* XSUM_WIN32_USE_WCHAR */
  158. #ifndef XSUM_API
  159. # ifdef XXH_INLINE_ALL
  160. # define XSUM_API static
  161. # else
  162. # define XSUM_API
  163. # endif
  164. #endif
  165. #ifndef XSUM_NO_TESTS
  166. # define XSUM_NO_TESTS 0
  167. #endif
  168. /* ***************************
  169. * Basic types
  170. * ***************************/
  171. #if defined(__cplusplus) /* C++ */ \
  172. || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) /* C99 */
  173. # include <stdint.h>
  174. typedef uint8_t XSUM_U8;
  175. typedef uint32_t XSUM_U32;
  176. typedef uint64_t XSUM_U64;
  177. # else
  178. # include <limits.h>
  179. typedef unsigned char XSUM_U8;
  180. # if UINT_MAX == 0xFFFFFFFFUL
  181. typedef unsigned int XSUM_U32;
  182. # else
  183. typedef unsigned long XSUM_U32;
  184. # endif
  185. typedef unsigned long long XSUM_U64;
  186. #endif /* not C++/C99 */
  187. #endif /* XSUM_CONFIG_H */