modified: myjupyterlab.sh
[GalaxyCodeBases.git] / c_cpp / lib / htslib / cram / os.h
blobb1fdca62097d9e3c7ff7b150ccd256b3f8db1b3e
1 /*
2 Copyright (c) 1993, 1995-2002 MEDICAL RESEARCH COUNCIL
3 All rights reserved
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1 Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
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.
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.
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.
33 Copyright (c) 2004, 2006, 2009-2011, 2013, 2017 Genome Research Ltd.
34 Author: James Bonfield <jkb@sanger.ac.uk>
36 Redistribution and use in source and binary forms, with or without
37 modification, are permitted provided that the following conditions are met:
39 1. Redistributions of source code must retain the above copyright notice,
40 this list of conditions and the following disclaimer.
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.
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.
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.
63 * File: os.h
65 * Author:
66 * MRC Laboratory of Molecular Biology
67 * Hills Road
68 * Cambridge CB2 2QH
69 * United Kingdom
71 * Description: operating system specific type definitions
75 #ifndef _OS_H_
76 #define _OS_H_
78 #include <limits.h>
79 #include <inttypes.h>
80 #include "htslib/hts_endian.h"
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
87 /*-----------------------------------------------------------------------------
88 * Byte swapping macros
92 * Our new swap runs at the same speed on Ultrix, but substantially faster
93 * (300% for swap_int4, ~50% for swap_int2) on an Alpha (due to the lack of
94 * decent 'char' support).
96 * They also have the ability to swap in situ (src == dst). Newer code now
97 * relies on this so don't change back!
99 #define iswap_int8(x) \
100 (((x & 0x00000000000000ffLL) << 56) + \
101 ((x & 0x000000000000ff00LL) << 40) + \
102 ((x & 0x0000000000ff0000LL) << 24) + \
103 ((x & 0x00000000ff000000LL) << 8) + \
104 ((x & 0x000000ff00000000LL) >> 8) + \
105 ((x & 0x0000ff0000000000LL) >> 24) + \
106 ((x & 0x00ff000000000000LL) >> 40) + \
107 ((x & 0xff00000000000000LL) >> 56))
109 #define iswap_int4(x) \
110 (((x & 0x000000ff) << 24) + \
111 ((x & 0x0000ff00) << 8) + \
112 ((x & 0x00ff0000) >> 8) + \
113 ((x & 0xff000000) >> 24))
115 #define iswap_int2(x) \
116 (((x & 0x00ff) << 8) + \
117 ((x & 0xff00) >> 8))
120 * Linux systems may use byteswap.h to get assembly versions of byte-swap
121 * on intel systems. This can be as trivial as the bswap opcode, which works
122 * out at over 2-times faster than iswap_int4 above.
124 #if 0
125 #if defined(__linux__)
126 # include <byteswap.h>
127 # undef iswap_int8
128 # undef iswap_int4
129 # undef iswap_int2
130 # define iswap_int8 bswap_64
131 # define iswap_int4 bswap_32
132 # define iswap_int2 bswap_16
133 #endif
134 #endif
138 * Macros to specify that data read in is of a particular endianness.
139 * The macros here swap to the appropriate order for the particular machine
140 * running the macro and return the new answer. These may also be used when
141 * writing to a file to specify that we wish to write in (eg) big endian
142 * format.
144 * This leads to efficient code as most of the time these macros are
145 * trivial.
147 #if defined(HTS_BIG_ENDIAN)
148 #define le_int4(x) iswap_int4((x))
149 #define le_int2(x) iswap_int2((x))
150 #elif defined(HTS_LITTLE_ENDIAN)
151 #define le_int4(x) (x)
152 #define le_int2(x) (x)
153 #else
154 static inline uint32_t le_int4(uint32_t x) {
155 return le_to_u32((uint8_t *) &x);
157 static inline uint16_t le_int2(uint16_t x) {
158 return le_to_u16((uint8_t *) &x);
160 #endif
162 /*-----------------------------------------------------------------------------
163 * <inttypes.h> definitions, incase they're not present
166 #ifndef PRId64
167 #define __PRI64__ "l"
168 #define PRId64 __PRI64__ "d"
169 #define PRId32 "d"
170 #define PRId16 "d"
171 #define PRId8 "d"
172 #define PRIu64 __PRI64__ "u"
173 #define PRIu32 "u"
174 #define PRIu16 "u"
175 #define PRIu8 "u"
176 #endif
178 /*-----------------------------------------------------------------------------
179 * Operating system specifics.
180 * These ought to be done by autoconf, but are legacy code.
183 * SunOS 4.x
184 * Even though we use the ANSI gcc, we make use the the standard SunOS 4.x
185 * libraries and include files, which are non-ansi
187 #if defined(__sun__) && !defined(__svr4__)
188 #define SEEK_SET 0
189 #define SEEK_CUR 1
190 #define SEEK_END 2
191 #endif
194 * Microsoft Visual C++
195 * Windows
197 #if defined(_MSC_VER)
198 #define popen _popen
199 #define pclose _pclose
200 #define ftruncate(fd,len) _chsize(fd,len)
201 #endif
205 * Microsoft Windows running MinGW
207 #if defined(__MINGW32__)
208 /* #define mkdir(filename,mode) mkdir((filename)) */
209 #define sysconf(x) 512
210 #define ftruncate(fd,len) _chsize(fd,len)
211 #endif
213 /* Generic WIN32 API issues */
214 #ifdef _WIN32
215 # ifndef HAVE_FSEEKO
216 # if __MSVCRT_VERSION__ >= 0x800
217 /* if you have MSVCR80 installed then you can use these definitions: */
218 # define off_t __int64
219 # define fseeko _fseeki64
220 # define ftello _ftelli64
221 # else
222 /* otherwise we're stuck with 32-bit file support */
223 # define off_t long
224 # define fseeko fseek
225 # define ftello ftell
226 # endif
227 # endif /* !HAVE_FSEEKO */
228 #endif /* _WIN32 */
230 #ifdef __cplusplus
232 #endif
234 #endif /*_OS_H_*/