os.h 9.1 KB

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