Mercurial > repos > youngkim > ezbamqc
comparison ezBAMQC/src/htslib/cram/os.h @ 0:dfa3745e5fd8
Uploaded
author | youngkim |
---|---|
date | Thu, 24 Mar 2016 17:12:52 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:dfa3745e5fd8 |
---|---|
1 /* | |
2 Copyright (c) 1993, 1995-2002 MEDICAL RESEARCH COUNCIL | |
3 All rights reserved | |
4 | |
5 Redistribution and use in source and binary forms, with or without | |
6 modification, are permitted provided that the following conditions are met: | |
7 | |
8 1 Redistributions of source code must retain the above copyright notice, | |
9 this list of conditions and the following disclaimer. | |
10 | |
11 2 Redistributions in binary form must reproduce the above copyright notice, | |
12 this list of conditions and the following disclaimer in the documentation | |
13 and/or other materials provided with the distribution. | |
14 | |
15 3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF | |
16 MOLECULAR BIOLOGY nor the names of its contributors may be used to endorse or | |
17 promote products derived from this software without specific prior written | |
18 permission. | |
19 | |
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 */ | |
31 | |
32 /* | |
33 Copyright (c) 2004, 2006, 2009-2011, 2013 Genome Research Ltd. | |
34 Author: James Bonfield <jkb@sanger.ac.uk> | |
35 | |
36 Redistribution and use in source and binary forms, with or without | |
37 modification, are permitted provided that the following conditions are met: | |
38 | |
39 1. Redistributions of source code must retain the above copyright notice, | |
40 this list of conditions and the following disclaimer. | |
41 | |
42 2. Redistributions in binary form must reproduce the above copyright notice, | |
43 this list of conditions and the following disclaimer in the documentation | |
44 and/or other materials provided with the distribution. | |
45 | |
46 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger | |
47 Institute nor the names of its contributors may be used to endorse or promote | |
48 products derived from this software without specific prior written permission. | |
49 | |
50 THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND | |
51 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
52 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
53 DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE | |
54 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
55 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
56 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
57 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
58 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
59 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
60 */ | |
61 | |
62 /* | |
63 * File: os.h | |
64 * | |
65 * Author: | |
66 * MRC Laboratory of Molecular Biology | |
67 * Hills Road | |
68 * Cambridge CB2 2QH | |
69 * United Kingdom | |
70 * | |
71 * Description: operating system specific type definitions | |
72 * | |
73 */ | |
74 | |
75 #ifndef _OS_H_ | |
76 #define _OS_H_ | |
77 | |
78 #include <limits.h> | |
79 #include <inttypes.h> | |
80 | |
81 #ifdef __cplusplus | |
82 extern "C" { | |
83 #endif | |
84 | |
85 /*----------------------------------------------------------------------------- | |
86 * Detection of endianness. The main part of this is done in autoconf, but | |
87 * for the case of MacOS FAT binaries we fall back on auto-sensing based on | |
88 * processor type too. | |
89 */ | |
90 | |
91 /* Set by autoconf */ | |
92 #define SP_LITTLE_ENDIAN | |
93 | |
94 /* Mac FAT binaries or unknown. Auto detect based on CPU type */ | |
95 #if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN) | |
96 | |
97 /* | |
98 * x86 equivalents | |
99 */ | |
100 #if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686) | |
101 # if defined(SP_BIG_ENDIAN) | |
102 # undef SP_BIG_ENDIAN | |
103 # endif | |
104 # define SP_LITTLE_ENDIAN | |
105 #endif | |
106 | |
107 /* | |
108 * DEC Alpha | |
109 */ | |
110 #if defined(__alpha__) || defined(__alpha) | |
111 # if defined(SP_LITTLE_ENDIAN) | |
112 # undef SP_LITTLE_ENDIAN | |
113 # endif | |
114 # define SP_BIG_ENDIAN | |
115 #endif | |
116 | |
117 /* | |
118 * SUN Sparc | |
119 */ | |
120 #if defined(__sparc__) || defined(__sparc) | |
121 # if defined(SP_LITTLE_ENDIAN) | |
122 # undef SP_LITTLE_ENDIAN | |
123 # endif | |
124 # define SP_BIG_ENDIAN | |
125 #endif | |
126 | |
127 /* | |
128 * PowerPC | |
129 */ | |
130 #if defined(__ppc__) || defined(__ppc) | |
131 # if defined(SP_LITTLE_ENDIAN) | |
132 # undef SP_LITTLE_ENDIAN | |
133 # endif | |
134 # define SP_BIG_ENDIAN | |
135 #endif | |
136 | |
137 /* Some catch-alls */ | |
138 #if defined(__LITTLE_ENDIAN__) || defined(__LITTLEENDIAN__) | |
139 # define SP_LITTLE_ENDIAN | |
140 #endif | |
141 | |
142 #if defined(__BIG_ENDIAN__) || defined(__BIGENDIAN__) | |
143 # define SP_BIG_ENDIAN | |
144 #endif | |
145 | |
146 #if defined(SP_BIG_ENDIAN) && defined(SP_LITTLE_ENDIAN) | |
147 # error Both BIG and LITTLE endian defined. Fix os.h and/or Makefile | |
148 #endif | |
149 | |
150 #if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN) | |
151 # error Neither BIG nor LITTLE endian defined. Fix os.h and/or Makefile | |
152 #endif | |
153 | |
154 #endif | |
155 | |
156 /*----------------------------------------------------------------------------- | |
157 * Allow for unaligned memory access. This is used in BAM code as the packed | |
158 * structure has 4-byte cigar ints after the variable length name. | |
159 * | |
160 * Consider using AX_CHECK_ALIGNED_ACCESS_REQUIRED in autoconf. | |
161 */ | |
162 #if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686) | |
163 # define ALLOW_UAC | |
164 #endif | |
165 | |
166 /*----------------------------------------------------------------------------- | |
167 * Byte swapping macros | |
168 */ | |
169 | |
170 /* | |
171 * Our new swap runs at the same speed on Ultrix, but substantially faster | |
172 * (300% for swap_int4, ~50% for swap_int2) on an Alpha (due to the lack of | |
173 * decent 'char' support). | |
174 * | |
175 * They also have the ability to swap in situ (src == dst). Newer code now | |
176 * relies on this so don't change back! | |
177 */ | |
178 #define iswap_int8(x) \ | |
179 (((x & 0x00000000000000ffLL) << 56) + \ | |
180 ((x & 0x000000000000ff00LL) << 40) + \ | |
181 ((x & 0x0000000000ff0000LL) << 24) + \ | |
182 ((x & 0x00000000ff000000LL) << 8) + \ | |
183 ((x & 0x000000ff00000000LL) >> 8) + \ | |
184 ((x & 0x0000ff0000000000LL) >> 24) + \ | |
185 ((x & 0x00ff000000000000LL) >> 40) + \ | |
186 ((x & 0xff00000000000000LL) >> 56)) | |
187 | |
188 #define iswap_int4(x) \ | |
189 (((x & 0x000000ff) << 24) + \ | |
190 ((x & 0x0000ff00) << 8) + \ | |
191 ((x & 0x00ff0000) >> 8) + \ | |
192 ((x & 0xff000000) >> 24)) | |
193 | |
194 #define iswap_int2(x) \ | |
195 (((x & 0x00ff) << 8) + \ | |
196 ((x & 0xff00) >> 8)) | |
197 | |
198 /* | |
199 * Linux systems may use byteswap.h to get assembly versions of byte-swap | |
200 * on intel systems. This can be as trivial as the bswap opcode, which works | |
201 * out at over 2-times faster than iswap_int4 above. | |
202 */ | |
203 #if 0 | |
204 #if defined(__linux__) | |
205 # include <byteswap.h> | |
206 # undef iswap_int8 | |
207 # undef iswap_int4 | |
208 # undef iswap_int2 | |
209 # define iswap_int8 bswap_64 | |
210 # define iswap_int4 bswap_32 | |
211 # define iswap_int2 bswap_16 | |
212 #endif | |
213 #endif | |
214 | |
215 | |
216 /* | |
217 * Macros to specify that data read in is of a particular endianness. | |
218 * The macros here swap to the appropriate order for the particular machine | |
219 * running the macro and return the new answer. These may also be used when | |
220 * writing to a file to specify that we wish to write in (eg) big endian | |
221 * format. | |
222 * | |
223 * This leads to efficient code as most of the time these macros are | |
224 * trivial. | |
225 */ | |
226 #ifdef SP_BIG_ENDIAN | |
227 #define le_int4(x) iswap_int4((x)) | |
228 #define le_int2(x) iswap_int2((x)) | |
229 #endif | |
230 | |
231 #ifdef SP_LITTLE_ENDIAN | |
232 #define le_int4(x) (x) | |
233 #define le_int2(x) (x) | |
234 #endif | |
235 | |
236 /*----------------------------------------------------------------------------- | |
237 * <inttypes.h> definitions, incase they're not present | |
238 */ | |
239 | |
240 #ifndef PRId64 | |
241 #define __PRI64__ "l" | |
242 #define PRId64 __PRI64__ "d" | |
243 #define PRId32 "d" | |
244 #define PRId16 "d" | |
245 #define PRId8 "d" | |
246 #define PRIu64 __PRI64__ "u" | |
247 #define PRIu32 "u" | |
248 #define PRIu16 "u" | |
249 #define PRIu8 "u" | |
250 #endif | |
251 | |
252 /*----------------------------------------------------------------------------- | |
253 * Operating system specifics. | |
254 * These ought to be done by autoconf, but are legacy code. | |
255 */ | |
256 /* | |
257 * SunOS 4.x | |
258 * Even though we use the ANSI gcc, we make use the the standard SunOS 4.x | |
259 * libraries and include files, which are non-ansi | |
260 */ | |
261 #if defined(__sun__) && !defined(__svr4__) | |
262 #define SEEK_SET 0 | |
263 #define SEEK_CUR 1 | |
264 #define SEEK_END 2 | |
265 #endif | |
266 | |
267 /* | |
268 * Microsoft Visual C++ | |
269 * Windows | |
270 */ | |
271 #if defined(_MSC_VER) | |
272 #define popen _popen | |
273 #define pclose _pclose | |
274 #define ftruncate(fd,len) _chsize(fd,len) | |
275 #endif | |
276 | |
277 | |
278 /* | |
279 * Microsoft Windows running MinGW | |
280 */ | |
281 #if defined(__MINGW32__) | |
282 /* #define mkdir(filename,mode) mkdir((filename)) */ | |
283 #define sysconf(x) 512 | |
284 #define ftruncate(fd,len) _chsize(fd,len) | |
285 #endif | |
286 | |
287 /* Generic WIN32 API issues */ | |
288 #ifdef _WIN32 | |
289 # ifndef HAVE_FSEEKO | |
290 # if __MSVCRT_VERSION__ >= 0x800 | |
291 /* if you have MSVCR80 installed then you can use these definitions: */ | |
292 # define off_t __int64 | |
293 # define fseeko _fseeki64 | |
294 # define ftello _ftelli64 | |
295 # else | |
296 /* otherwise we're stuck with 32-bit file support */ | |
297 # define off_t long | |
298 # define fseeko fseek | |
299 # define ftello ftell | |
300 # endif | |
301 # endif /* !HAVE_FSEEKO */ | |
302 #endif /* _WIN32 */ | |
303 | |
304 #ifdef __cplusplus | |
305 } | |
306 #endif | |
307 | |
308 #endif /*_OS_H_*/ |