1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "air.h" |
25 |
|
|
|
26 |
|
|
/* |
27 |
|
|
******** airMyEndian() |
28 |
|
|
** |
29 |
|
|
** determine at run-time if we are little (1234) or big (4321) endian |
30 |
|
|
*/ |
31 |
|
|
int |
32 |
|
|
airMyEndian(void) { |
33 |
|
|
int tmpI, ret; |
34 |
|
|
char leastbyte; |
35 |
|
|
|
36 |
|
|
/* set int to 1: |
37 |
|
|
least signficant byte will be 1, |
38 |
|
|
most signficant byte will be 0 */ |
39 |
|
|
tmpI = 1; |
40 |
|
|
/* cast address of (4-byte) int to char*, and dereference, |
41 |
|
|
which retrieves the byte at the low-address-end of int |
42 |
|
|
(the "first" byte in memory ordering). |
43 |
|
|
On big endian, we're getting the most significant byte (0); |
44 |
|
|
on little endian, we're getting least significant byte (1) */ |
45 |
|
|
leastbyte = *(AIR_CAST(char*, &tmpI)); |
46 |
✓✗ |
155284 |
if (leastbyte) { |
47 |
|
|
ret = airEndianLittle; |
48 |
|
77642 |
} else { |
49 |
|
|
ret = airEndianBig; |
50 |
|
|
} |
51 |
|
77642 |
return ret; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
static const char * |
55 |
|
|
_airEndianStr[] = { |
56 |
|
|
"(unknown endian)", |
57 |
|
|
"little", |
58 |
|
|
"big" |
59 |
|
|
}; |
60 |
|
|
|
61 |
|
|
static const char * |
62 |
|
|
_airEndianDesc[] = { |
63 |
|
|
"unknown endianness", |
64 |
|
|
"Intel and compatible", |
65 |
|
|
"Everyone besides Intel and compatible" |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
static const int |
69 |
|
|
_airEndianVal[] = { |
70 |
|
|
airEndianUnknown, |
71 |
|
|
airEndianLittle, |
72 |
|
|
airEndianBig, |
73 |
|
|
}; |
74 |
|
|
|
75 |
|
|
static const airEnum |
76 |
|
|
_airEndian = { |
77 |
|
|
"endian", |
78 |
|
|
2, |
79 |
|
|
_airEndianStr, _airEndianVal, |
80 |
|
|
_airEndianDesc, |
81 |
|
|
NULL, NULL, |
82 |
|
|
AIR_FALSE |
83 |
|
|
}; |
84 |
|
|
|
85 |
|
|
const airEnum *const |
86 |
|
|
airEndian = &_airEndian; |
87 |
|
|
|