Ignore:
Timestamp:
Apr 22, 2011, 4:12:56 AM (11 years ago)
Author:
Sam Hocevar
Message:

core: replace all byte swapping macros with inline functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/common.h

    r524 r525  
    1616//
    1717#include <stdint.h>
     18#include <stdio.h>
    1819
    1920//
     
    4041}
    4142
    42 static inline uint16_t Swap16(uint16_t x)
     43static inline uint16_t lstl(uint16_t x)
    4344{
    44     return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8);
     45    if (BigEndian())
     46        return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8);
     47    return x;
    4548}
    4649
    47 static inline uint32_t Swap32(uint32_t x)
     50static inline uint32_t lltl(uint32_t x)
    4851{
    49     return ((uint32_t)x >> 24) | (((uint32_t)x & 0x00ff0000) >> 8)
    50          | (((uint32_t)x & 0x0000ff00) << 8) | ((uint32_t)x << 24);
     52    if (BigEndian())
     53        return ((uint32_t)x >> 24) | (((uint32_t)x & 0x00ff0000) >> 8)
     54             | (((uint32_t)x & 0x0000ff00) << 8) | ((uint32_t)x << 24);
     55    return x;
    5156}
    5257
    53 #define uint16_to_intel(x) (BigEndian() ? Swap16((x)) : (x))
    54 #define uint32_to_intel(x) (BigEndian() ? Swap32((x)) : (x))
    55 #define big_uint16_to_local(x) (BigEndian() ? (x) : Swap16((x)))
    56 #define big_uint32_to_local(x) (BigEndian() ? (x) : Swap32((x)))
    57 #define uint16_to_local(x) (BigEndian() ? Swap16((x)) : (x))
    58 #define uint32_to_local(x) (BigEndian() ? Swap32((x)) : (x))
    59 
    60 #define bltl(x) big_uint32_to_local(x)
    61 #define bstl(x) big_uint16_to_local(x)
    62 #define lltl(x) uint32_to_intel(x)
    63 #define lstl(x) uint16_to_intel(x)
    64 
    65 #include <stdio.h>
    6658#define ERROR(x,st) { if (!(x)) \
    6759   { printf("Error on line %d of %s : %s\n", \
Note: See TracChangeset for help on using the changeset viewer.