Changeset 861 for libcaca/trunk/common.h
- Timestamp:
- Apr 24, 2006, 10:45:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/common.h
r859 r861 31 31 #endif 32 32 33 #if !defined(HAVE_HTONS) && !defined(HAVE_NETINET_IN_H) 34 # if defined(HAVE_ENDIAN_H) 35 # include <endian.h> 36 # endif 37 static extern inline uint16_t htons(uint16_t x) 38 { 39 #if defined(HAVE_ENDIAN_H) 40 if(__BYTE_ORDER == __BIG_ENDIAN) 41 #else 42 /* This is compile-time optimised with at least -O1 or -Os */ 43 uint32_t const dummy = 0x12345678; 44 if(*(uint8_t const *)&dummy == 0x12) 45 #endif 46 return x; 47 else 48 return (x >> 8) | (x << 8); 49 } 50 51 static extern inline uint32_t htonl(uint32_t x) 52 { 53 #if defined(HAVE_ENDIAN_H) 54 if(__BYTE_ORDER == __BIG_ENDIAN) 55 #else 56 /* This is compile-time optimised with at least -O1 or -Os */ 57 uint32_t const dummy = 0x12345678; 58 if(*(uint8_t const *)&dummy == 0x12) 59 #endif 60 return x; 61 else 62 return (x >> 24) | ((x >> 8) & 0x0000ff00) 63 | ((x << 8) & 0x00ff0000) | (x << 24); 64 } 65 #endif 66
Note: See TracChangeset
for help on using the changeset viewer.