commit 1066c216d10ab00c41500809f448f0ba90ae060d from: Omar Polo date: Sun Jul 02 10:32:04 2023 UTC add compat for endian.h commit - 291ecc472387b3e2c14aeb08563387771faa5192 commit + 1066c216d10ab00c41500809f448f0ba90ae060d blob - /dev/null blob + 2eb594e582e7573a0e5e2151b49beccff4cbc5bf (mode 644) --- /dev/null +++ compat/endian/endian.h @@ -0,0 +1,26 @@ +#include "../../config.h" + +#if HAVE_SYS_ENDIAN +# include +#elif HAVE_MACHINE_ENDIAN +# include +# include + +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htole16(x) OSSwapHostToLittleInt16(x) +# define be16toh(x) OSSwapBigToHostInt16(x) +# define le16toh(x) OSSwapLittleToHostInt16(x) + +# define htobe32(x) OSSwapHostToBigInt32(x) +# define htole32(x) OSSwapHostToLittleInt32(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +# define htobe64(x) OSSwapHostToBigInt64(x) +# define htole64(x) OSSwapHostToLittleInt64(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) +#else +# error no compatible endian.h header found +#endif + blob - 0568beae3e3931cda725af7b2d2299fc9626ee22 blob + 053c66ff95af1c3ffa35f541c552c619095dbfcf --- configure +++ configure @@ -135,6 +135,7 @@ COMPATS= HAVE_ACCEPT4= HAVE_ASR_RUN= HAVE_BUFFEREVENT_READ_PRESSURE_CB= +HAVE_ENDIAN=0 HAVE_ERR= HAVE_EVENT_ASR_RUN= HAVE_FREEZERO= @@ -145,6 +146,7 @@ HAVE_GETPROGNAME= HAVE_IMSG= HAVE_LIBEVENT= HAVE_LIBEVENT2= +HAVE_MACHINE_ENDIAN=0 HAVE_PLEDGE= HAVE_REALLOCARRAY= HAVE_RECALLOCARRAY= @@ -155,6 +157,7 @@ HAVE_SETRESUID= HAVE_STRLCAT= HAVE_STRLCPY= HAVE_STRTONUM= +HAVE_SYS_ENDIAN=0 HAVE_SYS_QUEUE= HAVE_SYS_TREE= HAVE_UNVEIL= @@ -262,6 +265,18 @@ fi if ! singletest WAIT_ANY WAIT_ANY; then CFLAGS="${CFLAGS} -DWAIT_ANY=-1" +fi + +runtest endian ENDIAN || \ +runtest machine_endian MACHINE_ENDIAN || \ +runtest sys_endian SYS_ENDIAN || true + +if [ "${HAVE_ENDIAN}" -eq 0 -a \ + "${HAVE_SYS_ENDIAN}" -eq 0 -a \ + "${HAVE_MACHINE_ENDIAN}" -eq 0 ]; then + echo "FATAL: no endian header found" 1>&2 + echo "FATAL: no endian header found" 1>&3 + exit 1 fi runtest accept4 ACCEPT4 -D_GNU_SOURCE || true @@ -329,6 +344,10 @@ fi # things we can provide by ourselves: +if [ "${HAVE_ENDIAN}" -eq 0 ]; then + CFLAGS="-I compat/endian ${CFLAGS}" +fi + if [ "${HAVE_IMSG}" -eq 0 ]; then CFLAGS="-I compat/imsg ${CFLAGS}" COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}" @@ -356,6 +375,7 @@ cat < + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +int +main(void) +{ + uint16_t x; + + x = 42; + return (htobe16(x)); +} blob - /dev/null blob + 2413b5896b13f658f73c6c73ab5100e41ec5e769 (mode 644) --- /dev/null +++ tests/machine_endian.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Omar Polo + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +main(void) +{ + uint16_t x; + + x = 42; + return (OSSwapHostToBigInt16(x)); +} blob - /dev/null blob + bba56c9ed2ea334c99fe1d986c895aae65f18011 (mode 644) --- /dev/null +++ tests/sys_endian.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Omar Polo + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +int +main(void) +{ + uint16_t x; + + x = 42; + return (htobe16(x)); +}