endian.c 812 B

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