add compat for endian (now required by imsg)

This commit is contained in:
Omar Polo 2023-07-02 09:14:44 +00:00
parent c9c44c6571
commit 5d2f4b1611
4 changed files with 112 additions and 0 deletions

30
configure vendored
View File

@ -244,6 +244,22 @@ if ! runtest wait_any WAIT_ANY; then
CFLAGS="${CFLAGS} -DWAIT_ANY=-1"
fi
HAVE_ENDIAN_H=0
HAVE_SYS_ENDIAN_H=0
HAVE_MACHINE_ENDIAN=0
runtest endian_h ENDIAN_H || \
runtest sys_endian_h SYS_ENDIAN_H || \
runtest machine_endian MACHINE_ENDIAN || true
if [ ${HAVE_ENDIAN_H} -eq 0 -a \
${HAVE_SYS_ENDIAN_H} -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 err ERR || true
runtest explicit_bzero EXPLICIT_BZERO || true
runtest freezero FREEZERO || true
@ -349,6 +365,20 @@ cat <<__HEREDOC__
__HEREDOC__
if [ ${HAVE_ENDIAN_H} -eq 1 ]; then
echo "#include <endian.h>"
elif [ ${HAVE_SYS_ENDIAN_H} -eq 1 ]; then
echo "#include <sys/endian.h>"
elif [ ${HAVE_MACHINE_ENDIAN} -eq 1 ]; then
cat <<__HEREDOC__
#include <machine/endian.h>
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
__HEREDOC__
fi
[ ${HAVE_EXPLICIT_BZERO} -eq 0 -o \
${HAVE_FREEZERO} -eq 0 -o \
${HAVE_REALLOCARRAY} -eq 0 -o \

27
have/endian_h.c Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Omar Polo <op@omarpolo.com>
*
* 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 <endian.h>
#include <stdint.h>
int
main(void)
{
uint16_t x;
x = 42;
return (htobe16(x));
}

28
have/machine_endian.c Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Omar Polo <op@omarpolo.com>
*
* 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 <machine/endian.h>
#include <libkern/OSByteOrder.h>
#include <stdint.h>
int
main(void)
{
uint16_t x;
x = 42;
return (OSSwapHostToBigInt16(x));
}

27
have/sys_endian_h.c Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 Omar Polo <op@omarpolo.com>
*
* 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 <sys/endian.h>
#include <stdint.h>
int
main(void)
{
uint16_t x;
x = 42;
return (htobe16(x));
}