support_endian.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H
10#define SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H
11
12#if HAVE_BYTESWAP_H
13#include <byteswap.h>
14#endif
15#if HAVE_MACHINE_BYTE_SWAP_H
16#include <machine/byte_swap.h>
17#endif
18#if HAVE_SYS_BSWAP_H
19#include <sys/bswap.h>
20#endif
21#if HAVE_ENDIAN_H
22#include <endian.h>
23#endif
24#if HAVE_SYS_ENDIAN_H
25#include <sys/endian.h>
26#endif
27
28/*
29 * Macros to deal with byte swapping. These macros provide
30 * the following interface:
31 *
32 * // Byte-swap
33 * uint16_t bswap16(uint16_t);
34 * uint32_t bswap32(uint32_t);
35 *
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);
41 *
42 * XXX: What about unusual byte orders like 3412 or 2143 ?
43 * Never had any problems reported, so we do not worry about them.
44 */
45
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)
51# else // 'hard way'
52# define bswap16(x) \
53 (((((uint16_t)(x)) >> 8) & 0xff) | ((((uint16_t)(x)) & 0xff) << 8))
54# endif
55#endif
56
57/* Define htole16() in terms of bswap16(). */
58# if defined(WORDS_BIGENDIAN)
59# define htole16(x) bswap16(x)
60# else
61# define htole16(x) (x)
62# endif
63#endif
64
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)
70# else // 'hard way'
71# define bswap32(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))
76# endif
77
78/* Define htole32() in terms of bswap32(). */
79#endif
80# if defined(WORDS_BIGENDIAN)
81# define htole32(x) bswap32(x)
82# else
83# define htole32(x) (x)
84# endif
85#endif
86
87/* Define letoh*() in terms of htole*(). The swap is symmetrical. */
88#if !HAVE_LE16TOH && !defined(le16toh)
89#define le16toh(x) htole16(x)
90#endif
91#if !HAVE_LE32TOH && !defined(le32toh)
92#define le32toh(x) htole32(x)
93#endif
94
95#endif /* SQUID_LIB_NTLMAUTH_SUPPORT_ENDIAN_H */
96

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors