endian.c 829 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * \file 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-2008 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. * \date 2001-2008
  16. */
  17. /**
  18. * \brief Tests for little ENDIAN.
  19. *
  20. * Test if machine is little or big endian.
  21. *
  22. * \return 1 little endian
  23. * \return 0 big endian
  24. */
  25. int G_is_little_endian(void)
  26. {
  27. union
  28. {
  29. int testWord;
  30. char testByte[sizeof(int)];
  31. } endianTest;
  32. endianTest.testWord = 1;
  33. if (endianTest.testByte[0] == 1)
  34. return 1; /* true: little endian */
  35. return 0; /* false: big endian */
  36. }