• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
27  * This contains various configuration parameters and feature detection for
28  * xxhsum.
29  *
30  * Similar to config.h in Autotools, this should be the first header included.
31  */
32 
33 #ifndef XSUM_CONFIG_H
34 #define XSUM_CONFIG_H
35 
36 
37 /* ************************************
38  *  Compiler Options
39  **************************************/
40 /*
41  * Disable Visual C's warnings when using the "insecure" CRT functions instead
42  * of the "secure" _s functions.
43  *
44  * These functions are not portable, and aren't necessary if you are using the
45  * original functions properly.
46  */
47 #if defined(_MSC_VER) || defined(_WIN32)
48 #  ifndef _CRT_SECURE_NO_WARNINGS
49 #    define _CRT_SECURE_NO_WARNINGS
50 #  endif
51 #endif
52 
53 /* Under Linux at least, pull in the *64 commands */
54 #ifndef _LARGEFILE64_SOURCE
55 #  define _LARGEFILE64_SOURCE
56 #endif
57 #ifndef _FILE_OFFSET_BITS
58 #  define _FILE_OFFSET_BITS 64
59 #endif
60 
61 /*
62  * So we can use __attribute__((__format__))
63  */
64 #ifdef __GNUC__
65 #  define XSUM_ATTRIBUTE(x) __attribute__(x)
66 #else
67 #  define XSUM_ATTRIBUTE(x)
68 #endif
69 
70 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) /* UNIX-like OS */ \
71    || defined(__midipix__) || defined(__VMS))
72 #  if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1-2001 (SUSv3) conformant */ \
73      || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)  /* BSD distros */
74 #    define XSUM_PLATFORM_POSIX_VERSION 200112L
75 #  else
76 #    if defined(__linux__) || defined(__linux)
77 #      ifndef _POSIX_C_SOURCE
78 #        define _POSIX_C_SOURCE 200112L  /* use feature test macro */
79 #      endif
80 #    endif
81 #    include <unistd.h>  /* declares _POSIX_VERSION */
82 #    if defined(_POSIX_VERSION)  /* POSIX compliant */
83 #      define XSUM_PLATFORM_POSIX_VERSION _POSIX_VERSION
84 #    else
85 #      define XSUM_PLATFORM_POSIX_VERSION 0
86 #    endif
87 #  endif
88 #endif
89 #if !defined(XSUM_PLATFORM_POSIX_VERSION)
90 #  define XSUM_PLATFORM_POSIX_VERSION -1
91 #endif
92 
93 #if !defined(S_ISREG)
94 #  define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
95 #endif
96 
97 
98 /* ************************************
99  * Windows helpers
100  **************************************/
101 
102 /*
103  * Whether to use the Windows UTF-16 APIs instead of the portable libc 8-bit
104  * ("ANSI") APIs.
105  *
106  * Windows is not UTF-8 clean by default, and the only way to access every file
107  * on the OS is to use UTF-16.
108  *
109  * Do note that xxhsum uses UTF-8 internally and only uses UTF-16 for command
110  * line arguments, console I/O, and opening files.
111  *
112  * Additionally, this guarantees all piped output is UTF-8.
113  */
114 #if defined(XSUM_WIN32_USE_WCHAR) && !defined(_WIN32)
115 /* We use Windows APIs, only use this on Windows. */
116 #  undef XSUM_WIN32_USE_WCHAR
117 #endif
118 
119 #ifndef XSUM_WIN32_USE_WCHAR
120 #  if defined(_WIN32)
121 #    include <wchar.h>
122 #    if WCHAR_MAX == 0xFFFFU /* UTF-16 wchar_t */
123 #       define XSUM_WIN32_USE_WCHAR 1
124 #    else
125 #       define XSUM_WIN32_USE_WCHAR 0
126 #    endif
127 #  else
128 #    define XSUM_WIN32_USE_WCHAR 0
129 #  endif
130 #endif
131 
132 #if !XSUM_WIN32_USE_WCHAR
133 /*
134  * It doesn't make sense to have one without the other.
135  * Due to XSUM_WIN32_USE_WCHAR being undef'd, this also handles
136  * non-WIN32 platforms.
137  */
138 #  undef  XSUM_WIN32_USE_WMAIN
139 #  define XSUM_WIN32_USE_WMAIN 0
140 #else
141 /*
142  * Whether to use wmain() or main().
143  *
144  * wmain() is preferred because we don't have to mess with internal hidden
145  * APIs.
146  *
147  * It always works on MSVC, but in MinGW, it only works on MinGW-w64 with the
148  * -municode flag.
149  *
150  * Therefore we have to use main() -- there is no better option.
151  */
152 #  ifndef XSUM_WIN32_USE_WMAIN
153 #    if defined(_UNICODE) || defined(UNICODE) /* MinGW -municode */ \
154         || defined(_MSC_VER) /* MSVC */
155 #      define XSUM_WIN32_USE_WMAIN 1
156 #    else
157 #      define XSUM_WIN32_USE_WMAIN 0
158 #    endif
159 #  endif
160 /*
161  * It is always good practice to define these to prevent accidental use of the
162  * ANSI APIs, even if the program primarily uses UTF-8.
163  */
164 #  ifndef _UNICODE
165 #    define _UNICODE
166 #  endif
167 #  ifndef UNICODE
168 #    define UNICODE
169 #  endif
170 #endif /* XSUM_WIN32_USE_WCHAR */
171 
172 #ifndef XSUM_API
173 #  ifdef XXH_INLINE_ALL
174 #    define XSUM_API static
175 #  else
176 #    define XSUM_API
177 #  endif
178 #endif
179 
180 #ifndef XSUM_NO_TESTS
181 #  define XSUM_NO_TESTS 0
182 #endif
183 
184 /* ***************************
185  * Basic types
186  * ***************************/
187 
188 #if defined(__cplusplus) /* C++ */ \
189  || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)  /* C99 */
190 #  include <stdint.h>
191     typedef uint8_t  XSUM_U8;
192     typedef uint32_t XSUM_U32;
193     typedef uint64_t XSUM_U64;
194 # else
195 #   include <limits.h>
196     typedef unsigned char      XSUM_U8;
197 #   if UINT_MAX == 0xFFFFFFFFUL
198       typedef unsigned int     XSUM_U32;
199 #   else
200       typedef unsigned long    XSUM_U32;
201 #   endif
202     typedef unsigned long long XSUM_U64;
203 #endif /* not C++/C99 */
204 
205 #endif /* XSUM_CONFIG_H */
206