]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/ntlmauth/support_endian.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H
10 #define SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H
15 #if HAVE_MACHINE_BYTE_SWAP_H
16 #include <machine/byte_swap.h>
19 #include <sys/bswap.h>
25 #include <sys/endian.h>
29 * Macros to deal with byte swapping. These macros provide
30 * the following interface:
33 * uint16_t bswap16(uint16_t);
34 * uint32_t bswap32(uint32_t);
36 * // Convert from host byte order to little-endian, and vice versa.
37 * uint16_t htole16(uint16_t);
38 * uint32_t htole32(uint32_t);
39 * uint16_t le16toh(uint16_t);
40 * uint32_t le32toh(uint32_t);
42 * XXX: What about unusual byte orders like 3412 or 2143 ?
43 * Never had any problems reported, so we dont worry about them.
46 #if !HAVE_HTOLE16 && !defined(htole16)
47 /* Define bswap16() in terms of bswap_16() or the hard way. */
48 #if !HAVE_BSWAP16 && !defined(bswap16)
49 # if HAVE_BSWAP_16 || defined(bswap_16)
50 # define bswap16(x) bswap_16(x)
53 (((((uint16_t)(x)) >> 8) & 0xff) | ((((uint16_t)(x)) & 0xff) << 8))
57 /* Define htole16() in terms of bswap16(). */
58 # if defined(WORDS_BIGENDIAN)
59 # define htole16(x) bswap16(x)
61 # define htole16(x) (x)
65 #if !HAVE_HTOLE32 && !defined(htole32)
66 #if ! HAVE_BSWAP32 && ! defined(bswap32)
67 /* Define bswap32() in terms of bswap_32() or the hard way. */
68 # if HAVE_BSWAP_32 || defined(bswap_32)
69 # define bswap32(x) bswap_32(x)
72 (((((uint32_t)(x)) & 0xff000000) >> 24) | \
73 ((((uint32_t)(x)) & 0x00ff0000) >> 8) | \
74 ((((uint32_t)(x)) & 0x0000ff00) << 8) | \
75 ((((uint32_t)(x)) & 0x000000ff) << 24))
78 /* Define htole32() in terms of bswap32(). */
80 # if defined(WORDS_BIGENDIAN)
81 # define htole32(x) bswap32(x)
83 # define htole32(x) (x)
87 /* Define letoh*() in terms of htole*(). The swap is symmetrical. */
88 #if !HAVE_LE16TOH && !defined(le16toh)
89 #define le16toh(x) htole16(x)
91 #if !HAVE_LE32TOH && !defined(le32toh)
92 #define le32toh(x) htole32(x)
95 #endif /* SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H */