summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-10-18 16:06:44 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-10-18 16:06:44 +0000
commitb0ddc35e53b92de74a5ae8ea96c520cb71032843 (patch)
treee0d084adb47f183640334acdd7799dd9ac2d6b48
parentc0e0402341d1743ceff4cfa3e25c0d42e8782dbf (diff)
downloadmandoc-b0ddc35e53b92de74a5ae8ea96c520cb71032843.tar.gz
Compat glue for the FreeBSD comparison function prototype for fts_open(3)
which differs from what most other systems use. While here, improve diagnostic output of ./configure tests.
-rwxr-xr-xconfigure37
-rw-r--r--configure.local.example3
-rw-r--r--mandocdb.c8
-rw-r--r--test-fts.c19
4 files changed, 51 insertions, 16 deletions
diff --git a/configure b/configure
index 38daf4ad..737dc703 100755
--- a/configure
+++ b/configure
@@ -53,6 +53,7 @@ HAVE_EFTYPE=
HAVE_ENDIAN=
HAVE_ERR=
HAVE_FTS=
+HAVE_FTS_COMPARE_CONST=
HAVE_GETLINE=
HAVE_GETSUBOPT=
HAVE_ISBLANK=
@@ -129,9 +130,9 @@ COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
# If yes, use the override, if no, do not decide anything yet.
# Arguments: lower-case test name, manual value
ismanual() {
- [ -z "${2}" ] && return 1
- echo "${1}: manual (${2})" 1>&2
- echo "${1}: manual (${2})" 1>&3
+ [ -z "${3}" ] && return 1
+ echo "${1}: manual (HAVE_${2}=${3})" 1>&2
+ echo "${1}: manual (HAVE_${2}=${3})" 1>&3
echo 1>&3
return 0
}
@@ -142,27 +143,27 @@ ismanual() {
# Arguments: lower-case test name, upper-case test name, additional CFLAGS
singletest() {
cat 1>&3 << __HEREDOC__
-${1}: testing...
+${1}${3}: testing...
${COMP} ${3} -o test-${1} test-${1}.c
__HEREDOC__
if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
- echo "${1}: ${CC} succeeded" 1>&3
+ echo "${1}${3}: ${CC} succeeded" 1>&3
else
- echo "${1}: ${CC} failed with $?" 1>&3
+ echo "${1}${3}: ${CC} failed with $?" 1>&3
echo 1>&3
return 1
fi
if ./test-${1} 1>&3 2>&3; then
- echo "${1}: yes" 1>&2
- echo "${1}: yes" 1>&3
+ echo "${1}${3}: yes" 1>&2
+ echo "${1}${3}: yes" 1>&3
echo 1>&3
eval HAVE_${2}=1
rm "test-${1}"
return 0
else
- echo "${1}: execution failed with $?" 1>&3
+ echo "${1}${3}: execution failed with $?" 1>&3
echo 1>&3
rm "test-${1}"
return 1
@@ -174,9 +175,9 @@ __HEREDOC__
# Arguments: lower case name, upper case name, additional CFLAGS
runtest() {
eval _manual=\${HAVE_${2}}
- ismanual "${1}" "${_manual}" && return 0
+ ismanual "${1}" "${2}" "${_manual}" && return 0
singletest "${1}" "${2}" "${3}" && return 0
- echo "${1}: no" 1>&2
+ echo "${1}${3}: no" 1>&2
eval HAVE_${2}=0
return 1
}
@@ -184,7 +185,7 @@ runtest() {
# Select a UTF-8 locale.
get_locale() {
[ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
- ismanual UTF8_LOCALE "$UTF8_LOCALE" && return 0
+ ismanual UTF8_LOCALE UTF_LOCALE "$UTF8_LOCALE" && return 0
echo "UTF8_LOCALE: testing..." 1>&3
UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
if [ -z "${UTF8_LOCALE}" ]; then
@@ -204,7 +205,6 @@ runtest be32toh ENDIAN || true
runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true
runtest EFTYPE EFTYPE || true
runtest err ERR || true
-runtest fts FTS || true
runtest getline GETLINE || true
runtest getsubopt GETSUBOPT || true
runtest isblank ISBLANK || true
@@ -234,6 +234,14 @@ if [ ${HAVE_ENDIAN} -eq 0 -a \
exit 1
fi
+if ismanual fts FTS ${HAVE_FTS}; then
+ HAVE_FTS_COMPARE_CONST=0
+elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then
+ HAVE_FTS=1
+else
+ runtest fts FTS || true
+fi
+
# --- wide character and locale support ---
if get_locale; then
runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
@@ -258,7 +266,7 @@ if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
fi
# --- ohash ---
-if ismanual ohash "${HAVE_OHASH}"; then
+if ismanual ohash OHASH "${HAVE_OHASH}"; then
:
elif [ -n "${LD_OHASH}" ]; then
runtest ohash OHASH "${LD_OHASH}" || true
@@ -320,6 +328,7 @@ cat << __HEREDOC__
#define HAVE_ENDIAN ${HAVE_ENDIAN}
#define HAVE_ERR ${HAVE_ERR}
#define HAVE_FTS ${HAVE_FTS}
+#define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
#define HAVE_GETLINE ${HAVE_GETLINE}
#define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
#define HAVE_ISBLANK ${HAVE_ISBLANK}
diff --git a/configure.local.example b/configure.local.example
index 1c68e4b5..b2549913 100644
--- a/configure.local.example
+++ b/configure.local.example
@@ -230,7 +230,8 @@ HAVE_DIRENT_NAMLEN=0
HAVE_ENDIAN=0
HAVE_EFTYPE=0
HAVE_ERR=0
-HAVE_FTS=0
+HAVE_FTS=0 # Setting this implies HAVE_FTS_COMPARE_CONST=0.
+HAVE_FTS_COMPARE_CONST=0 # Setting this implies HAVE_FTS=1.
HAVE_GETLINE=0
HAVE_GETSUBOPT=0
HAVE_ISBLANK=0
diff --git a/mandocdb.c b/mandocdb.c
index f8f91256..110bb66f 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -120,7 +120,11 @@ static void dbadd_mlink(const struct mlink *mlink);
static void dbprune(struct dba *);
static void dbwrite(struct dba *);
static void filescan(const char *);
+#if HAVE_FTS_COMPARE_CONST
+static int fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
static int fts_compare(const FTSENT **, const FTSENT **);
+#endif
static void mlink_add(struct mlink *, const struct stat *);
static void mlink_check(struct mpage *, struct mlink *);
static void mlink_free(struct mlink *);
@@ -547,7 +551,11 @@ usage:
* at the beginning, process directory entries in reverse alpha order.
*/
static int
+#if HAVE_FTS_COMPARE_CONST
+fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+#else
fts_compare(const FTSENT **a, const FTSENT **b)
+#endif
{
return -strcmp((*a)->fts_name, (*b)->fts_name);
}
diff --git a/test-fts.c b/test-fts.c
index dbee5292..23e44152 100644
--- a/test-fts.c
+++ b/test-fts.c
@@ -2,6 +2,13 @@
#include <sys/stat.h>
#include <fts.h>
#include <stdio.h>
+#include <string.h>
+
+#ifdef FTS_COMPARE_CONST
+int fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
+int fts_compare(const FTSENT **, const FTSENT **);
+#endif
int
main(void)
@@ -14,7 +21,7 @@ main(void)
argv[1] = (char *)NULL;
ftsp = fts_open((char * const *)argv,
- FTS_PHYSICAL | FTS_NOCHDIR, NULL);
+ FTS_PHYSICAL | FTS_NOCHDIR, fts_compare);
if (ftsp == NULL) {
perror("fts_open");
@@ -40,3 +47,13 @@ main(void)
return 0;
}
+
+int
+#ifdef FTS_COMPARE_CONST
+fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+#else
+fts_compare(const FTSENT **a, const FTSENT **b)
+#endif
+{
+ return strcmp((*a)->fts_name, (*b)->fts_name);
+}