comparison srf2fastq/io_lib-1.12.2/io_lib/os.h @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 /*
2 * File: os.h
3 *
4 * Author:
5 * MRC Laboratory of Molecular Biology
6 * Hills Road
7 * Cambridge CB2 2QH
8 * United Kingdom
9 *
10 * Description: operating system specific type definitions
11 *
12 */
13
14 #ifndef _OS_H_
15 #define _OS_H_
16
17 /*
18 * The autoconf setup doesn't use options.mk as the Makefile is rebuilt.
19 * I haven't worked out how to do the analogous via autoconf, so for now
20 * I take the easy approach and hard-code all formats to be enabled
21 */
22 #ifdef HAVE_CONFIG_H
23 #include "io_lib_config.h"
24 #define IOLIB_ABI
25 #define IOLIB_SCF
26 #define IOLIB_ALF
27 #define IOLIB_PLN
28 #define IOLIB_CTF
29 #define IOLIB_EXP
30 #define IOLIB_SFF
31 #endif
32
33 #include <limits.h>
34 #include <inttypes.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41 * Emulation of config.h stuff when not using autoconf
42 */
43 #ifndef HAVE_CONFIG_H
44 # ifndef HAVE_ZLIB
45 # define HAVE_ZLIB
46 # endif
47 # ifndef HAVE_SYS_WAIT_H
48 # define HAVE_SYS_WAIT_H
49 # endif
50 #endif
51
52 /*
53 *-----------------------------------------------------------------------------
54 * <inttypes.h> definitions, incase they're not present
55 *-----------------------------------------------------------------------------
56 */
57 #ifndef PRId64
58 #define __PRI64__ "l"
59 #define PRId64 __PRI64__ "d"
60 #define PRId32 "d"
61 #define PRId16 "d"
62 #define PRId8 "d"
63 #define PRIu64 __PRI64__ "u"
64 #define PRIu32 "u"
65 #define PRIu16 "u"
66 #define PRIu8 "u"
67 #endif
68
69
70 /*
71 *-----------------------------------------------------------------------------
72 * Operating system specifics
73 *-----------------------------------------------------------------------------
74 */
75 /*
76 * SunOS 4.x
77 * Even though we use the ANSI gcc, we make use the the standard SunOS 4.x
78 * libraries and include files, which are non-ansi
79 */
80 #if defined(__sun__) && !defined(__svr4__)
81 #define SEEK_SET 0
82 #define SEEK_CUR 1
83 #define SEEK_END 2
84 #define FOPEN_MAX 64
85 #define FILENAME_MAX 1024
86
87 /* Missing functions, defined in strings.c */
88 #define NOMEMMOVE
89 #define NOSTRERROR
90 #define BUGGY_SSCANF
91 #endif
92
93 /*
94 * SunOS 5.x - gcc or Sun's cc
95 */
96 #if (defined(__sun__) || defined(__sun)) && (defined(__svr4__) || defined(__SVR4))
97 # define IMAGEDISPLAY
98 # define NOSTRDUP
99 #endif
100
101 /*
102 * Microsoft Visual C++
103 * Windows
104 */
105 #if defined(_MSC_VER)
106 #define popen _popen
107 #define pclose _pclose
108 typedef int mode_t;
109 #define ftruncate(fd,len) _chsize(fd,len)
110 #define sysconf(x) 512
111 #define NOPIPE
112 #define NOLOCKF
113 #define NOSTRCASECMP
114 #define NO_STRPTIME
115 #undef HAVE_SYS_WAIT_H
116 #endif
117
118
119 /*
120 * Microsoft Windows running MinGW
121 */
122 #if defined(__MINGW32__)
123 /* #define mkdir(filename,mode) mkdir((filename)) */
124 #define NOPIPE
125 #define NOLOCKF
126 #define NO_STRPTIME
127 #define sysconf(x) 512
128 #define ftruncate(fd,len) _chsize(fd,len)
129 #undef HAVE_SYS_WAIT_H
130 #endif
131
132 /* Generic WIN32 API issues */
133 #ifdef _WIN32
134 # ifndef HAVE_FSEEKO
135 # if __MSVCRT_VERSION__ >= 0x800
136 /* if you have MSVCR80 installed then you can use these definitions: */
137 # define off_t __int64
138 # define fseeko _fseeki64
139 # define ftello _ftelli64
140 # else
141 /* otherwise we're stuck with 32-bit file support */
142 # define off_t long
143 # define fseeko fseek
144 # define ftello ftell
145 # endif
146 # endif /* !HAVE_FSEEKO */
147 #endif /* _WIN32 */
148
149 /*
150 * Linux on AMD64 also needs to use va_copy()
151 */
152 #if defined(__linux__) && defined(__amd64__)
153 # ifndef NEED_VA_COPY
154 # define NEED_VA_COPY
155 # endif
156 #endif
157
158 /*
159 * DEC Alpha's running Digital UNIX
160 */
161 #if defined(__alpha)
162 /* Nothing as yet */
163 #endif
164
165 /*
166 * Silicon Graphics - Irix
167 */
168 #if defined(__sgi)
169 #define NOSTRDUP
170 #define NO_STRPTIME
171 #endif
172
173 /*
174 * Macs (<= OS 9) - yuk!
175 */
176 #if defined(MAC)
177 #define NOSTRDUP
178 #endif
179
180 #if defined(__APPLE__) && defined(__ppc__)
181 #define NO_STRPTIME
182 #define NOLOCKF
183 #endif
184
185 #if defined(__APPLE__) && defined(__i386__)
186 /* nothing untoward as yet */
187 #endif
188
189 /*
190 *-----------------------------------------------------------------------------
191 * Machine endianness.
192 * These are overridden at the end when using autoconf, but are here for
193 * when being built as part of the Staden Package.
194 *-----------------------------------------------------------------------------
195 */
196
197 /*
198 * First guess via autoconf. This is here as endianness can only be computed
199 * by autoconf for the machine we're building on. Hence cross-compilations
200 * or MacOSX "fat binaries" cannot work via autoconf in this manner.
201 *
202 * These provide a default for when the machine specific ifdefs below do you
203 * catch your system type.
204 */
205 #ifdef HAVE_CONFIG_H
206 # if defined(WORDS_BIGENDIAN)
207 # ifdef SP_LITTLE_ENDIAN
208 # undef SP_LITTLE_ENDIAN
209 # endif
210 # define SP_BIG_ENDIAN
211 # else
212 # ifdef SP_BIG_ENDIAN
213 # undef SP_BIG_ENDIAN
214 # endif
215 # define SP_LITTLE_ENDIAN
216 # endif
217 #endif
218
219 /*
220 * x86 equivalents
221 */
222 #if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64)
223 # if defined(SP_BIG_ENDIAN)
224 # undef SP_BIG_ENDIAN
225 # endif
226 # define SP_LITTLE_ENDIAN
227 #endif
228
229 /*
230 * DEC Alpha
231 */
232 #if defined(__alpha__) || defined(__alpha)
233 # if defined(SP_LITTLE_ENDIAN)
234 # undef SP_LITTLE_ENDIAN
235 # endif
236 # define SP_BIG_ENDIAN
237 #endif
238
239 /*
240 * SUN Sparc
241 */
242 #if defined(__sparc__) || defined(__sparc)
243 # if defined(SP_LITTLE_ENDIAN)
244 # undef SP_LITTLE_ENDIAN
245 # endif
246 # define SP_BIG_ENDIAN
247 #endif
248
249 /*
250 * PowerPC
251 */
252 #if defined(__ppc__) || defined(__ppc)
253 # if defined(SP_LITTLE_ENDIAN)
254 # undef SP_LITTLE_ENDIAN
255 # endif
256 # define SP_BIG_ENDIAN
257 #endif
258
259 /* Some catch-alls */
260 #if defined(__LITTLE_ENDIAN__) || defined(__LITTLEENDIAN__)
261 # define SP_LITTLE_ENDIAN
262 #endif
263
264 #if defined(__BIG_ENDIAN__) || defined(__BIGENDIAN__)
265 # define SP_BIG_ENDIAN
266 #endif
267
268 #if defined(SP_BIG_ENDIAN) && defined(SP_LITTLE_ENDIAN)
269 # error Both BIG and LITTLE endian defined. Fix os.h and/or Makefile
270 #endif
271
272 #if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN)
273 # error Neither BIG nor LITTLE endian defined. Fix os.h and/or Makefile
274 #endif
275
276
277 /*
278 *-----------------------------------------------------------------------------
279 * Typedefs for data sizes. Note there's umpteen versions of typedefs here
280 * due to old code being supported. The ones that should be used everywhere
281 * are {u,}int[124].
282 *
283 * C9X defines its own versions of these in inttypes.h so new code should
284 * ideally be using the (for example) int32_t style of types.
285 *-----------------------------------------------------------------------------
286 */
287
288 /*
289 * One byte integers
290 */
291 typedef unsigned char int1;
292 typedef unsigned char uint1;
293
294 /*
295 * Two byte integers
296 */
297 typedef signed short int2;
298 typedef unsigned short uint2;
299
300 /*
301 * Four byte integers
302 */
303 typedef signed int int4;
304 typedef unsigned int uint4;
305
306 typedef int64_t int8;
307 typedef uint64_t uint8;
308
309 /*
310 * Backwards compatibility
311 */
312 typedef signed char int_1;
313 typedef unsigned char uint_1;
314 typedef signed short int_2;
315 typedef unsigned short uint_2;
316 typedef signed int int_4;
317 typedef unsigned int uint_4;
318
319
320 /*
321 *-----------------------------------------------------------------------------
322 * The FORTRAN interface.
323 *-----------------------------------------------------------------------------
324 */
325
326 typedef int4 f_int;
327 typedef int4 f_implicit;
328 typedef void f_proc_ret; /* procedure return value */
329
330 /* James Bonfield compatability mode */
331 typedef int4 int_f; /* f_int */
332 typedef int4 int_fl; /* f_implicit */
333
334 #define f_proc_return() return /* (f_proc_ret) 0 */
335
336 /*
337 * Use when calling/defining a Fortran function from C.
338 */
339 #ifdef VMS
340 # define FORT(symbol) (symbol)
341 #else
342 # define FORT(symbol) (_symbol)
343 #endif
344
345
346 /*
347 *-----------------------------------------------------------------------------
348 * Some handy definitions.
349 *-----------------------------------------------------------------------------
350 */
351
352 #define MAXINT8 (9223372036854775807LL)
353 #define MAXINT4 (INT_MAX)
354 #define MAXINT2 (SHRT_MAX)
355
356
357 /*
358 *=============================================================================
359 * Anything below here should not be changed.
360 *=============================================================================
361 */
362
363 #define False 0
364 #define True 1
365
366
367 /*
368 * Our new swap runs at the same speed on Ultrix, but substantially faster
369 * (300% for swap_int4, ~50% for swap_int2) on an Alpha (due to the lack of
370 * decent 'char' support).
371 *
372 * They also have the ability to swap in situ (src == dst). Newer code now
373 * relies on this so don't change back!
374 */
375 #define iswap_int8(x) \
376 (((x & 0x00000000000000ffLL) << 56) + \
377 ((x & 0x000000000000ff00LL) << 40) + \
378 ((x & 0x0000000000ff0000LL) << 24) + \
379 ((x & 0x00000000ff000000LL) << 8) + \
380 ((x & 0x000000ff00000000LL) >> 8) + \
381 ((x & 0x0000ff0000000000LL) >> 24) + \
382 ((x & 0x00ff000000000000LL) >> 40) + \
383 ((x & 0xff00000000000000LL) >> 56))
384
385 #define iswap_int4(x) \
386 (((x & 0x000000ff) << 24) + \
387 ((x & 0x0000ff00) << 8) + \
388 ((x & 0x00ff0000) >> 8) + \
389 ((x & 0xff000000) >> 24))
390
391 #define iswap_int2(x) \
392 (((x & 0x00ff) << 8) + \
393 ((x & 0xff00) >> 8))
394
395 #define swap_int8(src, dst) ((dst) = iswap_int8(src))
396 #define swap_int4(src, dst) ((dst) = iswap_int4(src))
397 #define swap_int2(src, dst) ((dst) = iswap_int2(src))
398
399
400 /*
401 * Linux systems may use byteswap.h to get assembly versions of byte-swap
402 * on intel systems. This can be as trivial as the bswap opcode, which works
403 * out at over 2-times faster than iswap_int4 above.
404 */
405 #if 0
406 #if defined(__linux__)
407 # include <byteswap.h>
408 # undef iswap_int8
409 # undef iswap_int4
410 # undef iswap_int2
411 # define iswap_int8 bswap_64
412 # define iswap_int4 bswap_32
413 # define iswap_int2 bswap_16
414 #endif
415 #endif
416
417
418 /*
419 * Macros to specify that data read in is of a particular endianness.
420 * The macros here swap to the appropriate order for the particular machine
421 * running the macro and return the new answer. These may also be used when
422 * writing to a file to specify that we wish to write in (eg) big endian
423 * format.
424 *
425 * This leads to efficient code as most of the time these macros are
426 * trivial.
427 */
428 #ifdef SP_BIG_ENDIAN
429 #define be_int8(x) (x)
430 #define be_int4(x) (x)
431 #define be_int2(x) (x)
432 #define be_int1(x) (x)
433
434 #define le_int8(x) iswap_int8((x))
435 #define le_int4(x) iswap_int4((x))
436 #define le_int2(x) iswap_int2((x))
437 #define le_int1(x) (x)
438 #endif
439
440 #ifdef SP_LITTLE_ENDIAN
441 #define be_int8(x) iswap_int8((x))
442 #define be_int4(x) iswap_int4((x))
443 #define be_int2(x) iswap_int2((x))
444 #define be_int1(x) (x)
445
446 #define le_int8(x) (x)
447 #define le_int4(x) (x)
448 #define le_int2(x) (x)
449 #define le_int1(x) (x)
450 #endif
451
452 #ifdef __cplusplus
453 }
454 #endif
455
456 #endif /*_OS_H_*/