comparison th_endian2.h @ 0:bd61a80a6c54

Initial import into Mercurial repository. Discarding old cvs/svn history here, because it's cluttered and commit messages are mostly crap.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Mar 2008 04:41:58 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bd61a80a6c54
1 /*
2 * Endianess handling
3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2002-2007 Tecnic Software productions (TNSP)
5 *
6 * Please read file 'COPYING' for information on license and distribution.
7 */
8 #if (!defined(TH_RNAME) || !defined(TH_FILE) || !defined(TH_FREAD) || !defined(TH_FGETC))
9 #error Some required preprocessor macros NOT defined, but th_endian2.h included!
10 #endif
11
12 #ifdef TH_CODE_ENDIAN2
13 BOOL TH_RNAME(STR) (TH_FILE *f, uint8_t *s, size_t l)
14 {
15 return (TH_FREAD(s, sizeof(uint8_t), l, f) == l);
16 }
17
18
19 uint16_t TH_RNAME(BE16) (TH_FILE *f)
20 {
21 return (((uint16_t) TH_FGETC(f)) << 8) |
22 ((uint16_t) TH_FGETC(f));
23 }
24
25
26 uint32_t TH_RNAME(BE32) (TH_FILE *f)
27 {
28 return (((uint32_t) TH_FGETC(f)) << 24) |
29 (((uint32_t) TH_FGETC(f)) << 16) |
30 (((uint32_t) TH_FGETC(f)) << 8) |
31 ((uint32_t) TH_FGETC(f));
32 }
33
34
35 uint16_t TH_RNAME(LE16) (TH_FILE *f)
36 {
37 return ((uint16_t) TH_FGETC(f)) |
38 (((uint16_t) TH_FGETC(f)) << 8);
39 }
40
41
42 uint32_t TH_RNAME(LE32) (TH_FILE *f)
43 {
44 return ((uint32_t) TH_FGETC(f)) |
45 (((uint32_t) TH_FGETC(f)) << 8) |
46 (((uint32_t) TH_FGETC(f)) << 16) |
47 (((uint32_t) TH_FGETC(f)) << 24);
48 }
49 #endif