GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
endian.c
Go to the documentation of this file.
1 /*!
2  * \file lib/gis/endian.c
3  *
4  * \brief GIS Library - Functions to determine architecture endian.
5  *
6  * This endian test was taken from ./src.contrib/GMSL/NVIZ2.2/TOGL/apps/image.c.
7  *
8  * (C) 2001-2009 by the GRASS Development Team
9  *
10  * This program is free software under the GNU General Public License
11  * (>=v2). Read the file COPYING that comes with GRASS for details.
12  *
13  * \author Markus Neteler
14  */
15 
16 /*!
17  * \brief Tests for little ENDIAN.
18  *
19  * Test if machine is little or big endian.
20  *
21  * \return 1 little endian
22  * \return 0 big endian
23  */
25 {
26  union
27  {
28  int testWord;
29  char testByte[sizeof(int)];
30  } endianTest;
31 
32  endianTest.testWord = 1;
33 
34  if (endianTest.testByte[0] == 1)
35  return 1; /* true: little endian */
36 
37  return 0; /* false: big endian */
38 }
int G_is_little_endian(void)
Tests for little ENDIAN.
Definition: endian.c:24