aboutsummaryrefslogtreecommitdiffstats
path: root/com32/include/netinet/in.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-08-11 13:16:13 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-08-11 13:16:13 -0700
commit0757cb3d6b64e810212024ca51bedbf16120fc6e (patch)
treefde51dc0af81778430ba7e7b549ac41ea1630b57 /com32/include/netinet/in.h
parente32f5182161fd5210e67ae57136e929dc20e0776 (diff)
downloadsyslinux-0757cb3d6b64e810212024ca51bedbf16120fc6e.tar.gz
syslinux-0757cb3d6b64e810212024ca51bedbf16120fc6e.tar.xz
syslinux-0757cb3d6b64e810212024ca51bedbf16120fc6e.zip
netinet/in.h: adjust hton/ntoh macros to be true constants
Tweak the hton/ntoh macros so that they are true constants if the input is a constant expression; this makes them usable in the preprocessor. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/include/netinet/in.h')
-rw-r--r--com32/include/netinet/in.h31
1 files changed, 20 insertions, 11 deletions
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index 582632c9..97458bf9 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -5,36 +5,45 @@
#include <stdint.h>
+#define __htons_macro(v) (((v) << 8) | ((v) >> 8))
+
static inline uint16_t __htons(uint16_t v)
{
- return ((v) << 8) | ((v) >> 8);
+ return __htons_macro(v);
}
-#define htons(x) __htons(x)
-#define ntohs(x) __htons(x)
+#define htons(x) (__builtin_constant_p(x) ? __htons_macro(x) : __htons(x))
+#define ntohs(x) htons(x)
+
+#define __htonl_macro(v) ((((v) & 0x000000ff) << 24) | \
+ (((v) & 0x0000ff00) << 8) | \
+ (((v) & 0x00ff0000) >> 8) | \
+ (((v) & 0xff000000) >> 24))
static inline uint32_t __htonl(uint32_t v)
{
if (__builtin_constant_p(v)) {
- return (((v) & 0x000000ff) << 24) |
- (((v) & 0x0000ff00) << 8) |
- (((v) & 0x00ff0000) >> 8) | (((v) & 0xff000000) >> 24);
+ return __htonl_macro(v);
} else {
-asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0":"+q"(v));
+ asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0":"+q"(v));
return v;
}
}
-#define htonl(x) __htonl(x)
-#define ntohl(x) __htonl(x)
+#define htonl(x) (__builtin_constant_p(x) ? __htonl_macro(x) : __htonl(x))
+#define ntohl(x) htonl(x)
+
+#define __htonq_macro(v) \
+ (((uint64_t)__htonl_macro((uint32_t)(v)) << 32) | \
+ (__htonl_macro((uint32_t)((v) >> 32))))
static inline uint64_t __htonq(uint64_t v)
{
return ((uint64_t) __htonl(v) << 32) | __htonl(v >> 32);
}
-#define htonq(x) __htonq(x)
-#define ntohq(x) __htonq(x)
+#define htonq(x) (__builtin_constant_p(x) ? __htonq_macro(x) : __htonq(x))
+#define ntohq(x) htonq(x)
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;