endian.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Asterisk architecture endianess compatibility definitions
  20. */
  21. #ifndef _ASTERISK_ENDIAN_H
  22. #define _ASTERISK_ENDIAN_H
  23. /*
  24. * Autodetect system endianess
  25. */
  26. #ifndef __BYTE_ORDER
  27. #ifdef __linux__
  28. #include <endian.h>
  29. #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__APPLE__)
  30. #if defined(__OpenBSD__)
  31. #include "asterisk/compat.h"
  32. #endif
  33. #include <machine/endian.h>
  34. #define __BYTE_ORDER BYTE_ORDER
  35. #define __LITTLE_ENDIAN LITTLE_ENDIAN
  36. #define __BIG_ENDIAN BIG_ENDIAN
  37. #else
  38. #ifndef __LITTLE_ENDIAN
  39. #define __LITTLE_ENDIAN 1234
  40. #endif
  41. #ifndef __BIG_ENDIAN
  42. #define __BIG_ENDIAN 4321
  43. #endif
  44. #ifdef __LITTLE_ENDIAN__
  45. #define __BYTE_ORDER __LITTLE_ENDIAN
  46. #endif /* __LITTLE_ENDIAN */
  47. #if defined(i386) || defined(__i386__)
  48. #define __BYTE_ORDER __LITTLE_ENDIAN
  49. #endif /* defined i386 */
  50. #if defined(sun) && defined(unix) && defined(sparc)
  51. #define __BYTE_ORDER __BIG_ENDIAN
  52. #endif /* sun unix sparc */
  53. #endif /* linux */
  54. #endif /* __BYTE_ORDER */
  55. #ifndef __BYTE_ORDER
  56. #error Need to know endianess
  57. #endif /* __BYTE_ORDER */
  58. #endif /* _ASTERISK_ENDIAN_H */