From 9cb15d72bde6c3cd7e97bdeb7394f1b26cea8f2a Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 26 Mar 2019 19:13:43 -0400 Subject: [PATCH] netinet/in: Use the GCC4 builtin byteswap functions for htonl. Fixes the build breakage caused by PulkoMandy's recent commit. Remove these from ByteOrder.h now also, as per POSIX they should come from netinet/in.h. This is a small source compatibility breakage, but it will only affect a small portion of non-POSIX, partially-Be applications. --- headers/os/support/ByteOrder.h | 10 +--------- headers/posix/netinet/in.h | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/headers/os/support/ByteOrder.h b/headers/os/support/ByteOrder.h index d02cba1ac6..67b6879ac3 100644 --- a/headers/os/support/ByteOrder.h +++ b/headers/os/support/ByteOrder.h @@ -1,5 +1,5 @@ /* - * Copyright 2007 Haiku, Inc. All rights reserved. + * Copyright 2007, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _BYTE_ORDER_H @@ -23,14 +23,6 @@ typedef enum { } swap_action; -/* BSD/networking macros */ -#ifndef htonl -# define htonl(x) B_HOST_TO_BENDIAN_INT32(x) -# define ntohl(x) B_BENDIAN_TO_HOST_INT32(x) -# define htons(x) B_HOST_TO_BENDIAN_INT16(x) -# define ntohs(x) B_BENDIAN_TO_HOST_INT16(x) -#endif - /* always swap macros */ #define B_SWAP_DOUBLE(arg) __swap_double(arg) #define B_SWAP_FLOAT(arg) __swap_float(arg) diff --git a/headers/posix/netinet/in.h b/headers/posix/netinet/in.h index ab891cb8dd..786b978569 100644 --- a/headers/posix/netinet/in.h +++ b/headers/posix/netinet/in.h @@ -22,16 +22,19 @@ extern "C" { typedef uint16_t in_port_t; typedef uint32_t in_addr_t; -/* We can't include since we are a posix file, - * and we are not allowed to import all the BeOS types here. - */ -#ifndef htonl -# ifdef __HAIKU_BEOS_COMPATIBLE_TYPES - extern unsigned long __swap_int32(unsigned long); /* private */ +/* We can't include since we are a POSIX file, + * and we are not allowed to import all the BeOS types here. */ +#if !defined(__swap_int32) +# if __GNUC__ >= 4 +# define __swap_int32(arg) (uint32)__builtin_bswap32(arg) +# define __swap_int16(arg) (uint16)__builtin_bswap16(arg) # else - extern unsigned int __swap_int32(unsigned int); /* private */ + extern unsigned long __swap_int32(unsigned long); /* private */ + extern uint16_t __swap_int16(uint16_t); /* private */ # endif - extern uint16_t __swap_int16(uint16_t); /* private */ +#endif + +#ifndef htonl # if BYTE_ORDER == LITTLE_ENDIAN # define htonl(x) ((uint32_t)__swap_int32(x)) # define ntohl(x) ((uint32_t)__swap_int32(x))