123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #ifndef __M_SWAP__
- #define __M_SWAP__
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #ifdef HAVE_ASM_BYTEORDER_H
- #include <asm/byteorder.h>
- #ifdef __arch__swab16
- #define doom_swap_s (signed short)__arch__swab16
- #endif
- #ifdef __arch__swab32
- #define doom_swap_l (signed long)__arch__swab32
- #endif
- #endif /* HAVE_ASM_BYTEORDER_H */
- #ifdef HAVE_LIBKERN_OSBYTEORDER_H
- #include <libkern/OSByteOrder.h>
- #define doom_swap_s (short)OSSwapInt16
- #define doom_swap_l (long)OSSwapInt32
- #endif
- #ifndef doom_swap_l
- #define doom_swap_l(x) \
- ((long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
- (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
- (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
- (((unsigned long int)(x) & 0xff000000U) >> 24)))
- #endif
- #ifndef doom_swap_s
- #define doom_swap_s(x) \
- ((short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
- (((unsigned short int)(x) & 0xff00) >> 8)))
- #endif
- #ifdef WORDS_BIGENDIAN
- #define doom_wtohl(x) doom_swap_l(x)
- #define doom_htowl(x) doom_swap_l(x)
- #define doom_wtohs(x) doom_swap_s(x)
- #define doom_htows(x) doom_swap_s(x)
- #define doom_ntohl(x) doom_swap_l(x)
- #define doom_htonl(x) doom_swap_l(x)
- #define doom_ntohs(x) doom_swap_s(x)
- #define doom_htons(x) doom_swap_s(x)
- #else
- #define doom_wtohl(x) (long int)(x)
- #define doom_htowl(x) (long int)(x)
- #define doom_wtohs(x) (short int)(x)
- #define doom_htows(x) (short int)(x)
- #define doom_ntohl(x) (long int)(x)
- #define doom_htonl(x) (long int)(x)
- #define doom_ntohs(x) (short int)(x)
- #define doom_htons(x) (short int)(x)
- #endif
- #define LONG(x) doom_wtohl(x)
- #define SHORT(x) doom_htows(x)
- #endif
|