my_byteorder.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef MY_BYTEORDER_INCLUDED
  2. #define MY_BYTEORDER_INCLUDED
  3. /* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  14. /*
  15. Macro for reading 32-bit integer from network byte order (big-endian)
  16. from an unaligned memory location.
  17. */
  18. #define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) | \
  19. (((uint32) ((uchar) (A)[2])) << 8) | \
  20. (((uint32) ((uchar) (A)[1])) << 16) | \
  21. (((uint32) ((uchar) (A)[0])) << 24))
  22. /*
  23. Function-like macros for reading and storing in machine independent
  24. format (low byte first). There are 'korr' (assume 'corrector') variants
  25. for integer types, but 'get' (assume 'getter') for floating point types.
  26. */
  27. #if defined(__i386__) || defined(_WIN32)
  28. #define MY_BYTE_ORDER_ARCH_OPTIMIZED
  29. #include "byte_order_generic_x86.h"
  30. #elif defined(__x86_64__)
  31. #include "byte_order_generic_x86_64.h"
  32. #else
  33. #include "byte_order_generic.h"
  34. #endif
  35. /*
  36. Function-like macros for reading and storing in machine format from/to
  37. short/long to/from some place in memory V should be a variable (not on
  38. a register) and M a pointer to byte.
  39. */
  40. #ifdef WORDS_BIGENDIAN
  41. #include "big_endian.h"
  42. #else
  43. #include "little_endian.h"
  44. #endif
  45. #endif /* MY_BYTEORDER_INCLUDED */