]> Savannah Git Hosting - gnulib.git/commit
byteswap: port better to limited platforms
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 May 2024 22:48:33 +0000 (15:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 May 2024 22:49:13 +0000 (15:49 -0700)
commit3ecc7798749c254bb4ea7243eb3ec12d33325021
treee8c82d4f797ebc1d5915affe53c64f397fc12821
parent0e1464f640ddecc68d1714a641db023caa97dab5
byteswap: port better to limited platforms

POSIX does not require uint64_t, and the C standard
does not require uint16_t or uint32_t either, so port
to platforms that lack these types.  The POSIX limitation
is the only significant one in practice.  I ran into this
issue when updating Emacs, which still ports to platforms
lacking 64-bit types.
* lib/byteswap.in.h (bswap_16, bswap_32, bswap_64):
Accept and return uint_leastN_t instead of uintN_t,
for portability to non-POSIX hosts that lack uintN_t.
Almost no platforms these days lack the types, but
it’s easy to port so let’s do that.  Also, redo to avoid
unnecssary parentheses, as these are now functions not macros.
(bswap_64): Define only if UINT_LEAST64_MAX, for benefit
of not-quite-C99 platforms.  This is similar to what
bitrotate.h does.
* tests/test-byteswap.c (test_bswap_constant)
(test_bswap_eval_once, test_bswap_double) [!UINT_LEAST64_MAX]:
Do not test 64-bit swaps.
ChangeLog
lib/byteswap.in.h
tests/test-byteswap.c