File indexing completed on 2022-12-06 18:58:43

0001 /*
0002     SPDX-FileCopyrightText: 2009 Akarsh Simha <akarsh.simha@kdemail.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 /*
0008 NOTE: This file was written from scratch using several headers written
0009 by others as reference. Of particular mention is LICQ's
0010 licq_bytorder.h and Oskar Liljeblad's byteswap.h licensed under the
0011 GPL.
0012 */
0013 
0014 #ifndef BYTEORDER_H_
0015 #define BYTEORDER_H_
0016 
0017 // Check if we have standard byteswap headers
0018 
0019 #ifdef HAVE_BYTESWAP_H
0020 #include <byteswap.h>
0021 
0022 #elif defined HAVE_MACHINE_ENDIAN_H
0023 #include <machine/endian.h>
0024 #define bswap_16(x) swap16(x)
0025 #define bswap_32(x) swap32(x)
0026 
0027 #elif defined HAVE_SYS_BYTEORDER_H
0028 #include <sys/byteorder.h>
0029 #define bswap_16(x) BSWAP_16(x)
0030 #define bswap_32(x) BSWAP_32(x)
0031 #endif
0032 
0033 // If no standard headers are found, we define our own byteswap macros
0034 
0035 #ifndef bswap_16
0036 #define bswap_16(x) ((((x)&0x00FF) << 8) | (((x)&0xFF00) >> 8))
0037 #endif
0038 
0039 #ifndef bswap_32
0040 
0041 #define bswap_32(x) \
0042     ((((x)&0x000000FF) << 24) | (((x)&0x0000FF00) << 8) | (((x)&0x00FF0000) >> 8) | (((x)&0xFF000000) >> 24))
0043 #endif
0044 
0045 #endif