From 1bb4f8bb9e7406c14961365a652ce2e16ab7664c Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 5 Aug 2016 23:15:08 +0000 Subject: The concept of endianness seems to be somewhat newfangled, so the respective conversion functions are not yet properly standardized. Rumour has it that POSIX is working on it, though. For now, sprinkle some configuration glue. --- Makefile | 4 +++- configure | 21 +++++++++++++++++++++ configure.local.example | 3 +++ dba.c | 8 ++++++++ dba_write.c | 6 ++++++ dbm.c | 6 ++++++ dbm_map.c | 6 ++++++ test-be32toh.c | 11 +++++++++++ test-ntohl.c | 7 +++++++ 9 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test-be32toh.c create mode 100644 test-ntohl.c diff --git a/Makefile b/Makefile index 96f82cb2..f3f50c45 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,8 @@ VERSION = 1.14.0 # === LIST OF FILES ==================================================== -TESTSRCS = test-dirent-namlen.c \ +TESTSRCS = test-be32toh.c \ + test-dirent-namlen.c \ test-EFTYPE.c \ test-err.c \ test-fts.c \ @@ -28,6 +29,7 @@ TESTSRCS = test-dirent-namlen.c \ test-isblank.c \ test-mkdtemp.c \ test-nanosleep.c \ + test-ntohl.c \ test-ohash.c \ test-PATH_MAX.c \ test-pledge.c \ diff --git a/configure b/configure index def91028..f5d8f3e1 100755 --- a/configure +++ b/configure @@ -50,6 +50,7 @@ BUILD_CGI=0 HAVE_DIRENT_NAMLEN= HAVE_EFTYPE= +HAVE_ENDIAN= HAVE_ERR= HAVE_FTS= HAVE_GETLINE= @@ -57,6 +58,7 @@ HAVE_GETSUBOPT= HAVE_ISBLANK= HAVE_MKDTEMP= HAVE_NANOSLEEP= +HAVE_NTOHL= HAVE_OHASH= HAVE_PATH_MAX= HAVE_PLEDGE= @@ -72,6 +74,7 @@ HAVE_STRLCPY= HAVE_STRPTIME= HAVE_STRSEP= HAVE_STRTONUM= +HAVE_SYS_ENDIAN= HAVE_VASPRINTF= HAVE_WCHAR= @@ -197,6 +200,8 @@ get_locale() { # --- library functions --- runtest dirent-namlen DIRENT_NAMLEN || true +runtest be32toh ENDIAN || true +runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true runtest EFTYPE EFTYPE || true runtest err ERR || true runtest fts FTS || true @@ -204,6 +209,7 @@ runtest getline GETLINE || true runtest getsubopt GETSUBOPT || true runtest isblank ISBLANK || true runtest mkdtemp MKDTEMP || true +runtest ntohl NTOHL || true runtest PATH_MAX PATH_MAX || true runtest pledge PLEDGE || true runtest sandbox_init SANDBOX_INIT || true @@ -220,6 +226,14 @@ runtest strsep STRSEP || true runtest strtonum STRTONUM || true runtest vasprintf VASPRINTF || true +if [ ${HAVE_ENDIAN} -eq 0 -a \ + ${HAVE_SYS_ENDIAN} -eq 0 -a \ + ${HAVE_NTOHL} -eq 0 ]; then + echo "FATAL: no endian conversion functions found" 1>&2 + echo "FATAL: no endian conversion functions found" 1>&3 + exit 1 +fi + # --- wide character and locale support --- if get_locale; then runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true @@ -296,15 +310,21 @@ echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\"" [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\"" [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL" [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096" +if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then + echo "#define be32toh ntohl" + echo "#define htobe32 htonl" +fi cat << __HEREDOC__ #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN} +#define HAVE_ENDIAN ${HAVE_ENDIAN} #define HAVE_ERR ${HAVE_ERR} #define HAVE_FTS ${HAVE_FTS} #define HAVE_GETLINE ${HAVE_GETLINE} #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT} #define HAVE_ISBLANK ${HAVE_ISBLANK} #define HAVE_MKDTEMP ${HAVE_MKDTEMP} +#define HAVE_NTOHL ${HAVE_NTOHL} #define HAVE_PLEDGE ${HAVE_PLEDGE} #define HAVE_PROGNAME ${HAVE_PROGNAME} #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} @@ -318,6 +338,7 @@ cat << __HEREDOC__ #define HAVE_STRPTIME ${HAVE_STRPTIME} #define HAVE_STRSEP ${HAVE_STRSEP} #define HAVE_STRTONUM ${HAVE_STRTONUM} +#define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN} #define HAVE_VASPRINTF ${HAVE_VASPRINTF} #define HAVE_WCHAR ${HAVE_WCHAR} #define HAVE_OHASH ${HAVE_OHASH} diff --git a/configure.local.example b/configure.local.example index d9652f1d..1c68e4b5 100644 --- a/configure.local.example +++ b/configure.local.example @@ -227,6 +227,7 @@ CFLAGS="-g" # be regarded as successful). HAVE_DIRENT_NAMLEN=0 +HAVE_ENDIAN=0 HAVE_EFTYPE=0 HAVE_ERR=0 HAVE_FTS=0 @@ -234,6 +235,7 @@ HAVE_GETLINE=0 HAVE_GETSUBOPT=0 HAVE_ISBLANK=0 HAVE_MKDTEMP=0 +HAVE_NTOHL=0 HAVE_OHASH=0 HAVE_PATH_MAX=0 HAVE_PLEDGE=0 @@ -248,5 +250,6 @@ HAVE_STRLCPY=0 HAVE_STRPTIME=0 HAVE_STRSEP=0 HAVE_STRTONUM=0 +HAVE_SYS_ENDIAN=0 HAVE_VASPRINTF=0 HAVE_WCHAR=0 diff --git a/dba.c b/dba.c index 3104fbb2..d5fd5b85 100644 --- a/dba.c +++ b/dba.c @@ -17,8 +17,16 @@ * Allocation-based version of the mandoc database, for read-write access. * The interface is defined in "dba.h". */ +#include "config.h" + #include +#if HAVE_ENDIAN #include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif #include #include #include diff --git a/dba_write.c b/dba_write.c index 8b911f90..80574518 100644 --- a/dba_write.c +++ b/dba_write.c @@ -20,7 +20,13 @@ #include "config.h" #include +#if HAVE_ENDIAN #include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif #if HAVE_ERR #include #endif diff --git a/dbm.c b/dbm.c index 3b3ebef7..0576c002 100644 --- a/dbm.c +++ b/dbm.c @@ -20,7 +20,13 @@ #include "config.h" #include +#if HAVE_ENDIAN #include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif #if HAVE_ERR #include #endif diff --git a/dbm_map.c b/dbm_map.c index cae53553..b4d5bb80 100644 --- a/dbm_map.c +++ b/dbm_map.c @@ -24,7 +24,13 @@ #include #include +#if HAVE_ENDIAN #include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif #if HAVE_ERR #include #endif diff --git a/test-be32toh.c b/test-be32toh.c new file mode 100644 index 00000000..471e85ea --- /dev/null +++ b/test-be32toh.c @@ -0,0 +1,11 @@ +#ifdef SYS_ENDIAN +#include +#else +#include +#endif + +int +main(void) +{ + return htobe32(be32toh(0x3a7d0cdb)) != 0x3a7d0cdb; +} diff --git a/test-ntohl.c b/test-ntohl.c new file mode 100644 index 00000000..52dcc256 --- /dev/null +++ b/test-ntohl.c @@ -0,0 +1,7 @@ +#include + +int +main(void) +{ + return htonl(ntohl(0x3a7d0cdb)) != 0x3a7d0cdb; +} -- cgit