tuklib_integer: Fix building on OpenBSD/sparc64 that uses GCC 4.2

GCC 4.2 doesn't have __builtin_bswap16() and friends so tuklib_integer.h
tries to use OS-specific byte swap methods instead. On OpenBSD those
macros are swap16/32/64 instead of bswap16/32/64 like on other *BSDs
and Darwin.

An alternative to "#ifdef __OpenBSD__" could be "#ifdef swap16" as it
is a macro. But since OpenBSD seems to be a special case under this
special case of "*BSDs and Darwin", checking for __OpenBSD__ seems
the more conservative choice now.

Thanks to Christian Weisgerber and Brad Smith who both submitted
the same patch a few hours apart.

Co-authored-by: Christian Weisgerber <naddy@mips.inka.de>
Co-authored-by: Brad Smith <brad@comstyle.com>
Closes: https://github.com/tukaani-project/xz/pull/126
(cherry picked from commit 04b23addf3)
This commit is contained in:
Lasse Collin 2024-06-07 15:47:20 +03:00
parent 5522759d31
commit 6f66155e01
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
1 changed files with 9 additions and 3 deletions

View File

@ -86,9 +86,15 @@
#elif defined(HAVE_SYS_ENDIAN_H) #elif defined(HAVE_SYS_ENDIAN_H)
// *BSDs and Darwin // *BSDs and Darwin
# include <sys/endian.h> # include <sys/endian.h>
# ifdef __OpenBSD__
# define byteswap16(num) swap16(num)
# define byteswap32(num) swap32(num)
# define byteswap64(num) swap64(num)
# else
# define byteswap16(num) bswap16(num) # define byteswap16(num) bswap16(num)
# define byteswap32(num) bswap32(num) # define byteswap32(num) bswap32(num)
# define byteswap64(num) bswap64(num) # define byteswap64(num) bswap64(num)
# endif
#elif defined(HAVE_SYS_BYTEORDER_H) #elif defined(HAVE_SYS_BYTEORDER_H)
// Solaris // Solaris