bytes.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2005-2008 Team XBMC
  3. * http://www.xbmc.org
  4. * Copyright (C) 2008-2009 Andrej Stepanchuk
  5. * Copyright (C) 2009-2010 Howard Chu
  6. *
  7. * This file is part of librtmp.
  8. *
  9. * librtmp is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as
  11. * published by the Free Software Foundation; either version 2.1,
  12. * or (at your option) any later version.
  13. *
  14. * librtmp 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
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with librtmp see the file COPYING. If not, write to
  21. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301, USA.
  23. * http://www.gnu.org/copyleft/lgpl.html
  24. */
  25. #ifndef __BYTES_H__
  26. #define __BYTES_H__
  27. #include <stdint.h>
  28. #ifdef _WIN32
  29. /* Windows is little endian only */
  30. #define __LITTLE_ENDIAN 1234
  31. #define __BIG_ENDIAN 4321
  32. #define __BYTE_ORDER __LITTLE_ENDIAN
  33. #define __FLOAT_WORD_ORDER __BYTE_ORDER
  34. typedef unsigned char uint8_t;
  35. #else /* !_WIN32 */
  36. #include <sys/param.h>
  37. #if defined(BYTE_ORDER) && !defined(__BYTE_ORDER)
  38. #define __BYTE_ORDER BYTE_ORDER
  39. #endif
  40. #if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
  41. #define __BIG_ENDIAN BIG_ENDIAN
  42. #endif
  43. #if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
  44. #define __LITTLE_ENDIAN LITTLE_ENDIAN
  45. #endif
  46. #endif /* !_WIN32 */
  47. /* define default endianness */
  48. #ifndef __LITTLE_ENDIAN
  49. #define __LITTLE_ENDIAN 1234
  50. #endif
  51. #ifndef __BIG_ENDIAN
  52. #define __BIG_ENDIAN 4321
  53. #endif
  54. #ifndef __BYTE_ORDER
  55. #warning "Byte order not defined on your system, assuming little endian!"
  56. #define __BYTE_ORDER __LITTLE_ENDIAN
  57. #endif
  58. /* ok, we assume to have the same float word order and byte order if float word order is not defined */
  59. #ifndef __FLOAT_WORD_ORDER
  60. #warning "Float word order not defined, assuming the same as byte order!"
  61. #define __FLOAT_WORD_ORDER __BYTE_ORDER
  62. #endif
  63. #if !defined(__BYTE_ORDER) || !defined(__FLOAT_WORD_ORDER)
  64. #error "Undefined byte or float word order!"
  65. #endif
  66. #if __FLOAT_WORD_ORDER != __BIG_ENDIAN && __FLOAT_WORD_ORDER != __LITTLE_ENDIAN
  67. #error "Unknown/unsupported float word order!"
  68. #endif
  69. #if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN
  70. #error "Unknown/unsupported byte order!"
  71. #endif
  72. #endif