The attached patches fix some of these failures.

The remaining failures are:

> FAIL: test-areadlinkat
> ======================
> 
> ../../gltests/test-areadlinkat.c:78: assertion 'errno == EBADF' failed
> Abort
> FAIL test-areadlinkat (exit status: 134)
> 
> FAIL: test-cloexec
> ==================
> 
> ../../gltests/test-cloexec.c:102: assertion '!is_inheritable (fd2)' failed
> Abort
> FAIL test-cloexec (exit status: 134)
> 
> FAIL: test-dup2
> ===============
> 
> ../../gltests/test-dup2.c:192: assertion '!is_inheritable (fd + 1)' failed
> Abort
> FAIL test-dup2 (exit status: 134)
> 
> FAIL: test-faccessat
> ====================
> 
> ../../gltests/test-faccessat.c:36: assertion 'errno == EBADF' failed
> Abort
> FAIL test-faccessat (exit status: 134)
> 
> FAIL: test-fchdir
> =================
> 
> ../../gltests/test-fchdir.c:51: assertion 'errno == EBADF' failed
> Abort
> FAIL test-fchdir (exit status: 134)
> 
> FAIL: test-fchmodat
> ===================
> 
> ../../gltests/test-fchmodat.c:36: assertion 'errno == EBADF' failed
> Abort
> FAIL test-fchmodat (exit status: 134)
> 
> FAIL: test-fchownat
> ===================
> 
> ../../gltests/test-fchownat.c:73: assertion 'errno == EBADF' failed
> Abort
> FAIL test-fchownat (exit status: 134)
> 
> FAIL: test-fcntl
> ================
> 
> ../../gltests/test-fcntl.c:266: assertion 'errno == EINVAL' failed
> Abort
> FAIL test-fcntl (exit status: 134)
> 
> FAIL: test-fdopendir
> ====================
> 
> ../../gltests/test-fdopendir.c:51: assertion 'errno == EBADF' failed
> Abort
> FAIL test-fdopendir (exit status: 134)
> 
> FAIL: test-fpurge
> =================
> 
> ../../gltests/test-fpurge.c:91: assertion 'ftell (fp) == 8' failed
> Abort
> FAIL test-fpurge (exit status: 134)
> 
> FAIL: test-fstatat
> ==================
> 
> ../../gltests/test-fstatat.c:83: assertion 'errno == EBADF' failed
> Abort
> FAIL test-fstatat (exit status: 134)
> 
> FAIL: test-ftruncate.sh
> =======================
> 
> ../../gltests/test-ftruncate.c:52: assertion 'ftruncate (fd, 0) == -1' failed
> Abort
> FAIL test-ftruncate.sh (exit status: 134)
> 
> FAIL: test-futimens
> ===================
> 
> ../../gltests/test-futimens.h:121: assertion 'get_stat_atime_ns (&st1) == 
> get_stat_atime_ns (&st2)' failed
> Abort
> FAIL test-futimens (exit status: 134)
> 
> FAIL: test-getlogin_r
> =====================
> 
> ../../gltests/test-getlogin_r.c:47: assertion 'err == ERANGE || err == 
> EINVAL' failed
> Abort
> FAIL test-getlogin_r (exit status: 134)
> 
> FAIL: test-linkat
> =================
> 
> ../../gltests/test-linkat.c:102: assertion 'errno == EBADF' failed
> Abort
> FAIL test-linkat (exit status: 134)
> 
> FAIL: test-mkdirat
> ==================
> 
> ../../gltests/test-mkdirat.c:60: assertion 'mkdirat (-1, "foo", 0700) == -1' 
> failed
> Abort
> FAIL test-mkdirat (exit status: 134)
> 
> FAIL: test-mkfifoat
> ===================
> 
> ../../gltests/test-mkfifo.h:55: assertion 'func (BASE "fifo/", 0600) == -1' 
> failed
> Abort
> FAIL test-mkfifoat (exit status: 134)
> 
> FAIL: test-nonblocking-socket.sh
> ================================
> 
> ../../gltests/test-nonblocking-writer.h:101: assertion 'spent_time < 1.5' 
> failed
> Abort
> ../../gltests/test-nonblocking-socket.sh: line 4: 121456 Abort                
>    ./test-nonblocking-socket-main${EXEEXT} 
> ./test-nonblocking-socket-child${EXEEXT} 0
> ../../gltests/test-nonblocking-reader.h:164: assertion 'spent_time < 0.5' 
> failed
> Abort
> 
> FAIL: test-openat
> =================
> 
> ../../gltests/test-openat.c:68: assertion 'openat (-1, "foo", O_RDONLY) == 
> -1' failed
> Abort
> FAIL test-openat (exit status: 134)
> 
> FAIL: test-poll
> ===============
> 
> Unconnected socket test... test-poll hangs
> 
> FAIL test-poll (exit status: 143)
> 
> FAIL: test-posix_openpt
> =======================
> 
> ../../gltests/test-posix_openpt.c:58: assertion '0 <= slave' failed
> Abort
> FAIL test-posix_openpt (exit status: 134)
> 
> FAIL: test-readlinkat
> =====================
> 
> ../../gltests/test-readlinkat.c:66: assertion 'errno == EBADF' failed
> Abort
> FAIL test-readlinkat (exit status: 134)
> 
> FAIL: test-renameat
> ===================
> 
> ../../gltests/test-renameat.c:67: assertion 'renameat (-1, "foo", AT_FDCWD, 
> "bar") == -1' failed
> Abort
> FAIL test-renameat (exit status: 134)
> 
> FAIL: test-renameat2
> ====================
> 
> ../../gltests/test-renameat2.c:71: assertion 'errno == EBADF' failed
> Abort
> FAIL test-renameat2 (exit status: 134)
> 
> FAIL: test-statat
> =================
> 
> ../../gltests/test-fstatat.c:83: assertion 'errno == EBADF' failed
> Abort
> FAIL test-statat (exit status: 134)
> 
> FAIL: test-symlinkat
> ====================
> 
> ../../gltests/test-symlinkat.c:67: assertion 'errno == EBADF || errno == 
> ENOSYS' failed
> Abort
> FAIL test-symlinkat (exit status: 134)
> 
> FAIL: test-truncate
> ===================
> 
> ../../gltests/test-truncate.c:95: assertion 'truncate (BASE "file/", 0) == 
> -1' failed
> Abort
> FAIL test-truncate (exit status: 134)
> 
> FAIL: test-unlinkat
> ===================
> 
> ../../gltests/test-unlinkat.c:72: assertion 'errno == EBADF' failed
> Abort
> FAIL test-unlinkat (exit status: 134)
> 
> FAIL: test-unlockpt
> ===================
> 
> ../../gltests/test-unlockpt.c:36: assertion 'unlockpt (-1) == -1' failed
> Abort
> FAIL test-unlockpt (exit status: 134)
> 
> FAIL: test-utime
> ================
> 
> ../../gltests/test-utime.c:76: assertion 'utime (BASE "file/", &ts) == -1' 
> failed
> Abort
> FAIL test-utime (exit status: 134)
> 
> FAIL: test-utimens
> ==================
> 
> ../../gltests/test-utimens.h:94: assertion 'func (BASE "file/", ts) == -1' 
> failed
> Abort
> FAIL test-utimens (exit status: 134)
> 
> FAIL: test-utimensat
> ====================
> 
> ../../gltests/test-utimensat.c:76: assertion 'errno == EBADF' failed
> Abort
> FAIL test-utimensat (exit status: 134)

>From 5beeeb81c77cbcf72a7b9635fbad87e69432e6fd Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 10:49:55 +0100
Subject: [PATCH 1/7] math: Fix test failure on Haiku.

---
 ChangeLog                   |  8 ++++++++
 doc/posix-headers/math.texi |  5 +++++
 lib/math.in.h               | 13 +++++++++++--
 m4/ilogb.m4                 | 12 ++++++++++--
 m4/ilogbf.m4                | 12 ++++++++++--
 5 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3102b6b..bae2722 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	math: Fix test failure on Haiku.
+	* lib/math.in.h (FP_ILOGB0, FP_ILOGBNAN): Override on Haiku.
+	* m4/ilogb.m4 (gl_FUNC_ILOGB_WORKS): Update accordingly.
+	* m4/ilogbf.m4 (gl_FUNC_ILOGBF_WORKS): Likewise.
+	* doc/posix-headers/math.texi: Mention the Haiku problem.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	gnulib-tool: Avoid unnecessary config.h.in remaking in testdirs.
 	* gnulib-tool (func_create_testdir): Use workaround against 'autoheader'
 	bug reported at <https://savannah.gnu.org/support/index.php?109406>.
diff --git a/doc/posix-headers/math.texi b/doc/posix-headers/math.texi
index 0cf56a0..bc89238 100644
--- a/doc/posix-headers/math.texi
+++ b/doc/posix-headers/math.texi
@@ -37,6 +37,11 @@ platforms:
 NetBSD 5.1, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9.
 
 @item
+The macros @code{FP_ILOGB0} and @code{FP_ILOGBNAN} have wrong values on some
+platforms:
+Haiku 2017.
+
+@item
 The macros @code{NAN}, @code{HUGE_VALL}, and @code{INFINITY} are not
 defined on some platforms:
 OpenVMS.
diff --git a/lib/math.in.h b/lib/math.in.h
index f220151..09f822a 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -194,8 +194,17 @@ _NaN ()
 #endif
 
 
-/* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined.  */
-#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
+#if defined FP_ILOGB0 && defined FP_ILOGBNAN
+ /* Ensure FP_ILOGB0 and FP_ILOGBNAN are correct.  */
+# if defined __HAIKU__
+  /* Haiku: match what ilogb() does */
+#  undef FP_ILOGB0
+#  undef FP_ILOGBNAN
+#  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
+#  define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
+# endif
+#else
+ /* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined.  */
 # if defined __NetBSD__ || defined __sgi
   /* NetBSD, IRIX 6.5: match what ilogb() does */
 #  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
diff --git a/m4/ilogb.m4 b/m4/ilogb.m4
index 1d56ecb..a73d7ad 100644
--- a/m4/ilogb.m4
+++ b/m4/ilogb.m4
@@ -1,4 +1,4 @@
-# ilogb.m4 serial 2
+# ilogb.m4 serial 3
 dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -57,7 +57,15 @@ AC_DEFUN([gl_FUNC_ILOGB_WORKS],
 #include <limits.h>
 #include <math.h>
 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h.  */
-#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
+#if defined FP_ILOGB0 && defined FP_ILOGBNAN
+# if defined __HAIKU__
+  /* Haiku: match what ilogb() does */
+#  undef FP_ILOGB0
+#  undef FP_ILOGBNAN
+#  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
+#  define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
+# endif
+#else
 # if defined __NetBSD__ || defined __sgi
   /* NetBSD, IRIX 6.5: match what ilogb() does */
 #  define FP_ILOGB0   INT_MIN
diff --git a/m4/ilogbf.m4 b/m4/ilogbf.m4
index 4e16e07..a660108 100644
--- a/m4/ilogbf.m4
+++ b/m4/ilogbf.m4
@@ -1,4 +1,4 @@
-# ilogbf.m4 serial 2
+# ilogbf.m4 serial 3
 dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -59,7 +59,15 @@ AC_DEFUN([gl_FUNC_ILOGBF_WORKS],
 #include <limits.h>
 #include <math.h>
 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h.  */
-#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
+#if defined FP_ILOGB0 && defined FP_ILOGBNAN
+# if defined __HAIKU__
+  /* Haiku: match what ilogb() does */
+#  undef FP_ILOGB0
+#  undef FP_ILOGBNAN
+#  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
+#  define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
+# endif
+#else
 # if defined __NetBSD__ || defined __sgi
   /* NetBSD, IRIX 6.5: match what ilogbf() does */
 #  define FP_ILOGB0   INT_MIN
-- 
2.7.4

>From 6065f427d616ccc578b38d92a5ef27bc4b6286ea Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 11:16:56 +0100
Subject: [PATCH 2/7] expl: Ensure replacement on Haiku.

* m4/expl.m4 (gl_FUNC_EXPL): Test whether an expl() return value is
zero.
* doc/posix-functions/expl.texi: Mention the Haiku problem.
---
 ChangeLog                     |  7 ++++++
 doc/posix-functions/expl.texi |  5 ++++-
 m4/expl.m4                    | 50 ++++++++++++++++++++++++-------------------
 3 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bae2722..53745fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	expl: Ensure replacement on Haiku.
+	* m4/expl.m4 (gl_FUNC_EXPL): Test whether an expl() return value is
+	zero.
+	* doc/posix-functions/expl.texi: Mention the Haiku problem.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	math: Fix test failure on Haiku.
 	* lib/math.in.h (FP_ILOGB0, FP_ILOGBNAN): Override on Haiku.
 	* m4/ilogb.m4 (gl_FUNC_ILOGB_WORKS): Update accordingly.
diff --git a/doc/posix-functions/expl.texi b/doc/posix-functions/expl.texi
index 0a70d20..92d7ed6 100644
--- a/doc/posix-functions/expl.texi
+++ b/doc/posix-functions/expl.texi
@@ -12,7 +12,10 @@ Portability problems fixed by Gnulib:
 This function is missing on some platforms:
 FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @item
-This function returns NaN for small operands:
+This function returns 0.0 for all arguments on some platforms:
+Haiku 2017.
+@item
+This function returns NaN for small operands on some platforms:
 OpenBSD 5.4.
 @item
 This function is only defined as a macro with arguments on some platforms:
diff --git a/m4/expl.m4 b/m4/expl.m4
index 2eddf0a..42db88b 100644
--- a/m4/expl.m4
+++ b/m4/expl.m4
@@ -1,4 +1,4 @@
-# expl.m4 serial 10
+# expl.m4 serial 11
 dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -54,31 +54,37 @@ AC_DEFUN([gl_FUNC_EXPL],
       EXPL_LIBM=-lm
     fi
   fi
-  dnl On OpenBSD5.4 the system's native expl() is buggy:
+  dnl On Haiku 2017 the system's native expl() is just a stub: it returns 0.0
+  dnl and prints "__expl not implemented" for all arguments.
+  dnl On OpenBSD 5.4 the system's native expl() is buggy:
   dnl it returns 'nan' for small values. Test for this anomaly.
   if test $gl_cv_func_expl_no_libm = yes \
      || test $gl_cv_func_expl_in_libm = yes; then
     AC_CACHE_CHECK([whether expl() breaks with small values],
-        [gl_cv_func_expl_buggy],
-        [
-          save_LIBS="$LIBS"
-          LIBS="$EXPL_LIBM"
-          AC_RUN_IFELSE(
-           [AC_LANG_PROGRAM(
-             [[#include <math.h>]],
-             [[return isnan(expl(-1.0))||
-                      isnan(expl(-0.8))||
-                      isnan(expl(-0.4)); ]])],
-             [gl_cv_func_expl_buggy=no], [gl_cv_func_expl_buggy=yes],
-             [case $host_os in
-                openbsd*) gl_cv_func_expl_buggy="guessing yes" ;;
-                          # Guess no on native Windows.
-                mingw*)   gl_cv_func_expl_buggy="guessing no" ;;
-                *)        gl_cv_func_expl_buggy="guessing no" ;;
-              esac
-             ])
-          LIBS="$save_LIBS"
-        ])
+      [gl_cv_func_expl_buggy],
+      [save_LIBS="$LIBS"
+       LIBS="$EXPL_LIBM"
+       AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <math.h>]],
+            [[volatile long double x1 = -1.0;
+              volatile long double x2 = -0.8;
+              volatile long double x3 = -0.4;
+              return expl(x1) == 0.0 || isnan(expl(x1))
+                     || isnan(expl(x2)) || isnan(expl(x3));
+            ]])
+         ],
+         [gl_cv_func_expl_buggy=no], [gl_cv_func_expl_buggy=yes],
+         [case $host_os in
+            haiku* | openbsd*)
+                      gl_cv_func_expl_buggy="guessing yes" ;;
+                      # Guess no on native Windows.
+            mingw*)   gl_cv_func_expl_buggy="guessing no" ;;
+            *)        gl_cv_func_expl_buggy="guessing no" ;;
+          esac
+         ])
+       LIBS="$save_LIBS"
+      ])
     case "$gl_cv_func_expl_buggy" in
       *yes)
         gl_cv_func_expl_in_libm=no
-- 
2.7.4

>From 625f7aea332a6b43fd9be4ce91d805182a5feb0c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 12:57:35 +0100
Subject: [PATCH 3/7] ilogbl: Ensure replacement on Haiku.

* m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set
REPLACE_ILOGBL if ilogbl does not work.
(gl_FUNC_ILOGBL_WORKS): New macro.
* lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL.
* modules/math (Makefile.am): Substitute REPLACE_ILOGBL.
* modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL.
* doc/posix-functions/ilogbl.texi: Mention the Haiku problem.
---
 ChangeLog                       | 12 +++++++
 doc/posix-functions/ilogbl.texi |  3 ++
 lib/math.in.h                   | 13 +++++--
 m4/ilogbl.m4                    | 75 ++++++++++++++++++++++++++++++++++++++++-
 m4/math_h.m4                    |  3 +-
 modules/ilogbl                  | 10 +++---
 modules/math                    |  1 +
 7 files changed, 108 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 53745fc..9bfd408 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	ilogbl: Ensure replacement on Haiku.
+	* m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set
+	REPLACE_ILOGBL if ilogbl does not work.
+	(gl_FUNC_ILOGBL_WORKS): New macro.
+	* lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1.
+	* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL.
+	* modules/math (Makefile.am): Substitute REPLACE_ILOGBL.
+	* modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL.
+	* doc/posix-functions/ilogbl.texi: Mention the Haiku problem.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	expl: Ensure replacement on Haiku.
 	* m4/expl.m4 (gl_FUNC_EXPL): Test whether an expl() return value is
 	zero.
diff --git a/doc/posix-functions/ilogbl.texi b/doc/posix-functions/ilogbl.texi
index 9580a5c..f1ca24b 100644
--- a/doc/posix-functions/ilogbl.texi
+++ b/doc/posix-functions/ilogbl.texi
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
+@item
+This function returns a wrong result for denormalized arguments on some platforms:
+Haiku 2017.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/math.in.h b/lib/math.in.h
index 09f822a..5681597 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -1223,10 +1223,19 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
 #endif
 
 #if @GNULIB_ILOGBL@
-# if !@HAVE_ILOGBL@
+# if @REPLACE_ILOGBL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ilogbl
+#   define ilogbl rpl_ilogbl
+#  endif
+_GL_FUNCDECL_RPL (ilogbl, int, (long double x));
+_GL_CXXALIAS_RPL (ilogbl, int, (long double x));
+# else
+#  if !@HAVE_ILOGBL@
 _GL_FUNCDECL_SYS (ilogbl, int, (long double x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (ilogbl, int, (long double x));
+# endif
 _GL_CXXALIASWARN (ilogbl);
 #elif defined GNULIB_POSIXCHECK
 # undef ilogbl
diff --git a/m4/ilogbl.m4 b/m4/ilogbl.m4
index 44556a9..60cb141 100644
--- a/m4/ilogbl.m4
+++ b/m4/ilogbl.m4
@@ -1,4 +1,4 @@
-# ilogbl.m4 serial 1
+# ilogbl.m4 serial 2
 dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,8 +36,18 @@ AC_DEFUN([gl_FUNC_ILOGBL],
   LIBS="$save_LIBS"
   if test $gl_cv_func_ilogbl = yes; then
     ILOGBL_LIBM="$ILOGB_LIBM"
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $ILOGBL_LIBM"
+    gl_FUNC_ILOGBL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_ilogbl_works" in
+      *yes) ;;
+      *) REPLACE_ILOGBL=1 ;;
+    esac
   else
     HAVE_ILOGBL=0
+  fi
+  if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then
     dnl Find libraries needed to link lib/ilogbl.c.
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       ILOGBL_LIBM="$ILOGB_LIBM"
@@ -59,3 +69,66 @@ AC_DEFUN([gl_FUNC_ILOGBL],
   fi
   AC_SUBST([ILOGBL_LIBM])
 ])
+
+dnl Test whether ilogbl() works.
+dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
+dnl ca. 2^-16444 and ca. 2^-16382.
+AC_DEFUN([gl_FUNC_ILOGBL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <float.h>
+#include <math.h>
+/* Override the values of <float.h>, like done in float.in.h.  */
+#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+#endif
+#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+#endif
+#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP DBL_MIN_EXP
+#endif
+#if defined __sgi && (LDBL_MANT_DIG >= 106)
+# if defined __GNUC__
+#  undef LDBL_MIN_EXP
+#  define LDBL_MIN_EXP DBL_MIN_EXP
+# endif
+#endif
+volatile long double x;
+static int dummy (long double x) { return 0; }
+int main (int argc, char *argv[])
+{
+  int (*my_ilogbl) (long double) = argc ? ilogbl : dummy;
+  int result = 0;
+  /* This test fails on Haiku 2017.  */
+  {
+    int i;
+    for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long double)0.0; i--, x *= (long double)0.5)
+      if (my_ilogbl (x) != i - 1)
+        {
+          result |= 1;
+          break;
+        }
+  }
+  return result;
+}
+]])],
+        [gl_cv_func_ilogbl_works=yes],
+        [gl_cv_func_ilogbl_works=no],
+        [case "$host_os" in
+           haiku*) gl_cv_func_ilogbl_works="guessing no" ;;
+                   # Guess yes on native Windows.
+           mingw*) gl_cv_func_ilogbl_works="guessing yes" ;;
+           *)      gl_cv_func_ilogbl_works="guessing yes" ;;
+         esac
+        ])
+    ])
+])
diff --git a/m4/math_h.m4 b/m4/math_h.m4
index 6db72ca..b9a432e 100644
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 115
+# math_h.m4 serial 116
 dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -291,6 +291,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_HYPOTL=0;            AC_SUBST([REPLACE_HYPOTL])
   REPLACE_ILOGB=0;             AC_SUBST([REPLACE_ILOGB])
   REPLACE_ILOGBF=0;            AC_SUBST([REPLACE_ILOGBF])
+  REPLACE_ILOGBL=0;            AC_SUBST([REPLACE_ILOGBL])
   REPLACE_ISFINITE=0;          AC_SUBST([REPLACE_ISFINITE])
   REPLACE_ISINF=0;             AC_SUBST([REPLACE_ISINF])
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
diff --git a/modules/ilogbl b/modules/ilogbl
index d31ad26..3d321aa 100644
--- a/modules/ilogbl
+++ b/modules/ilogbl
@@ -10,14 +10,14 @@ m4/mathfunc.m4
 Depends-on:
 math
 extensions
-ilogb           [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-isfinite        [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-frexpl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-isnanl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+ilogb           [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+isfinite        [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+frexpl          [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isnanl          [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_ILOGBL
-if test $HAVE_ILOGBL = 0; then
+if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then
   AC_LIBOBJ([ilogbl])
 fi
 gl_MATH_MODULE_INDICATOR([ilogbl])
diff --git a/modules/math b/modules/math
index 2f553ba..d539518 100644
--- a/modules/math
+++ b/modules/math
@@ -260,6 +260,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
 	      -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \
 	      -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \
 	      -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \
+	      -e 's|@''REPLACE_ILOGBL''@|$(REPLACE_ILOGBL)|g' \
 	      -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
 	      -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
 	      -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
-- 
2.7.4

>From 34a992bf8faa8abb66e8666d76f47b685642918f Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 14:33:52 +0100
Subject: [PATCH 4/7] get-rusage-as: Avoid crash on Haiku.

---
 ChangeLog           | 5 +++++
 lib/get-rusage-as.c | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9bfd408..96a2f85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	get-rusage-as: Avoid crash on Haiku.
+	* lib/get-rusage-as.c: Avoid the setlimit-based implementation.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	ilogbl: Ensure replacement on Haiku.
 	* m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set
 	REPLACE_ILOGBL if ilogbl does not work.
diff --git a/lib/get-rusage-as.c b/lib/get-rusage-as.c
index 5de4e4e..eed2673 100644
--- a/lib/get-rusage-as.c
+++ b/lib/get-rusage-as.c
@@ -112,7 +112,7 @@
 
    BeOS, Haiku:
      a) On BeOS, there is no setrlimit function.
-        On Haiku, setrlimit exists. RLIMIT_AS is defined but unsupported.
+        On Haiku, setrlimit exists. RLIMIT_AS is defined but setrlimit fails.
      b) There is a specific BeOS API: get_next_area_info().
  */
 
@@ -150,7 +150,7 @@
 #include "vma-iter.h"
 
 
-#if HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT
+#if HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT && !defined __HAIKU__
 
 static uintptr_t
 get_rusage_as_via_setrlimit (void)
@@ -365,7 +365,7 @@ get_rusage_as (void)
   /* get_rusage_as_via_setrlimit() does not work.
      Prefer get_rusage_as_via_iterator().  */
   return get_rusage_as_via_iterator ();
-#elif HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT
+#elif HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT && !defined __HAIKU__
   /* Prefer get_rusage_as_via_setrlimit() if it succeeds,
      because the caller may want to use the result with setrlimit().  */
   uintptr_t result;
-- 
2.7.4

>From 93f03f40399e368f4b41ac169760596bf2dcd75d Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 14:34:21 +0100
Subject: [PATCH 5/7] get-rusage-data: Avoid crash on Haiku.

---
 ChangeLog             | 5 +++++
 lib/get-rusage-data.c | 7 +++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 96a2f85..66d0ef6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	get-rusage-data: Avoid crash on Haiku.
+	* lib/get-rusage-data.c: Avoid the setlimit-based implementation.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	get-rusage-as: Avoid crash on Haiku.
 	* lib/get-rusage-as.c: Avoid the setlimit-based implementation.
 
diff --git a/lib/get-rusage-data.c b/lib/get-rusage-data.c
index b55e727..1966a6e 100644
--- a/lib/get-rusage-data.c
+++ b/lib/get-rusage-data.c
@@ -121,8 +121,7 @@
 
    BeOS, Haiku:
      a) On BeOS, there is no setrlimit function.
-        On Haiku, setrlimit exists. RLIMIT_DATA is defined but unsupported:
-        getrlimit of RLIMIT_DATA always fails with errno = EINVAL.
+        On Haiku, setrlimit exists. RLIMIT_DATA is defined but setrlimit fails.
      b) There is a specific BeOS API: get_next_area_info().
  */
 
@@ -151,7 +150,7 @@
 #if !(defined __APPLE__ && defined __MACH__) || defined TEST
 /* Implement get_rusage_data_via_setrlimit().  */
 
-# if HAVE_SETRLIMIT && defined RLIMIT_DATA
+# if HAVE_SETRLIMIT && defined RLIMIT_DATA && !defined __HAIKU__
 
 #  ifdef _AIX
 #   define errno_expected() (errno == EINVAL || errno == EFAULT)
@@ -409,7 +408,7 @@ get_rusage_data (void)
   /* get_rusage_data_via_setrlimit() does not work.
      Prefer get_rusage_data_via_iterator().  */
   return get_rusage_data_via_iterator ();
-#elif HAVE_SETRLIMIT && defined RLIMIT_DATA
+#elif HAVE_SETRLIMIT && defined RLIMIT_DATA && !defined __HAIKU__
 # if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined _AIX || defined __hpux || defined __sgi || defined __osf__ || defined __sun /* Linux, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, IRIX, OSF/1, Solaris */
   /* get_rusage_data_via_setrlimit() works.  */
   return get_rusage_data_via_setrlimit ();
-- 
2.7.4

>From 411ad1157dd0d9ac9bafb545f03c3b5ae15cd22c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 17:33:22 +0100
Subject: [PATCH 6/7] strerror_r-posix: Fix behaviour and test failure on
 Haiku.

* lib/strerror_r.c (strerror_r): Don't assume that valid error numbers
are positive. Work around return value 0 instead of ERANGE on Haiku.
For unknown error numbers, use a format string consistent with perror().
* doc/posix-functions/strerror_r.texi: Mention the Haiku problem.
* tests/test-strerror_r.c (main): Don't assume that valid error numbers
are positive.
---
 ChangeLog                           | 10 ++++++++++
 doc/posix-functions/strerror_r.texi |  2 +-
 lib/strerror_r.c                    | 18 ++++++++++++++----
 tests/test-strerror_r.c             |  2 +-
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 66d0ef6..8539105 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	strerror_r-posix: Fix behaviour and test failure on Haiku.
+	* lib/strerror_r.c (strerror_r): Don't assume that valid error numbers
+	are positive. Work around return value 0 instead of ERANGE on Haiku.
+	For unknown error numbers, use a format string consistent with perror().
+	* doc/posix-functions/strerror_r.texi: Mention the Haiku problem.
+	* tests/test-strerror_r.c (main): Don't assume that valid error numbers
+	are positive.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	get-rusage-data: Avoid crash on Haiku.
 	* lib/get-rusage-data.c: Avoid the setlimit-based implementation.
 
diff --git a/doc/posix-functions/strerror_r.texi b/doc/posix-functions/strerror_r.texi
index 40a9465..220446a 100644
--- a/doc/posix-functions/strerror_r.texi
+++ b/doc/posix-functions/strerror_r.texi
@@ -62,7 +62,7 @@ HP-UX 11.31.
 When the buffer is too small and the value is in range, this function
 does not fail, but instead truncates the result and returns 0 on some
 platforms:
-AIX 6.1, OSF/1 5.1.
+AIX 6.1, OSF/1 5.1, Haiku 2017.
 @item
 When the value is not in range or the buffer is too small, this
 function fails to leave a NUL-terminated string in the buffer on some
diff --git a/lib/strerror_r.c b/lib/strerror_r.c
index e3a1c29..14e3195 100644
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -212,13 +212,16 @@ strerror_r (int errnum, char *buf, size_t buflen)
 # else
     ret = strerror_r (errnum, buf, buflen);
 
-    /* Some old implementations may return (-1, EINVAL) instead of EINVAL.  */
+    /* Some old implementations may return (-1, EINVAL) instead of EINVAL.
+       But on Haiku, valid error numbers are negative.  */
+#  if !defined __HAIKU__
     if (ret < 0)
       ret = errno;
+#  endif
 # endif
 
-# ifdef _AIX
-    /* AIX returns 0 rather than ERANGE when truncating strings; try
+# if defined _AIX || defined __HAIKU__
+    /* AIX and Haiku return 0 rather than ERANGE when truncating strings; try
        again until we are sure we got the entire string.  */
     if (!ret && strlen (buf) == buflen - 1)
       {
@@ -442,7 +445,14 @@ strerror_r (int errnum, char *buf, size_t buflen)
 #endif
 
     if (ret == EINVAL && !*buf)
-      snprintf (buf, buflen, "Unknown error %d", errnum);
+      {
+#if defined __HAIKU__
+        /* For consistency with perror().  */
+        snprintf (buf, buflen, "Unknown Application Error (%d)", errnum);
+#else
+        snprintf (buf, buflen, "Unknown error %d", errnum);
+#endif
+      }
 
     errno = saved_errno;
     return ret;
diff --git a/tests/test-strerror_r.c b/tests/test-strerror_r.c
index 16f99df..7a06ed6 100644
--- a/tests/test-strerror_r.c
+++ b/tests/test-strerror_r.c
@@ -108,7 +108,7 @@ main (void)
             errno = 0;
             ret = strerror_r (err, buf, i);
             ASSERT (errno == 0);
-            if (err < 0)
+            if (j == 2)
               ASSERT (ret == ERANGE || ret == EINVAL);
             else
               ASSERT (ret == ERANGE);
-- 
2.7.4

>From e369b04cca4da1534c98628b8ee4648bfca2bb3a Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 29 Oct 2017 21:01:06 +0100
Subject: [PATCH 7/7] Avoid several test failures with traditional locales on
 Haiku.

---
 ChangeLog       |  9 +++++++++
 m4/locale-ar.m4 | 23 +++++++++++++++--------
 m4/locale-fr.m4 | 27 +++++++++++++++++----------
 m4/locale-ja.m4 | 37 +++++++++++++++++++++++--------------
 m4/locale-zh.m4 | 37 +++++++++++++++++++++++--------------
 5 files changed, 87 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8539105..7fa915f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2017-10-29  Bruno Haible  <br...@clisp.org>
 
+	Avoid several test failures with traditional locales on Haiku.
+	* m4/locale-ar.m4 (gt_LOCALE_AR): On BeOS and Haiku, set LOCALE_AR=none.
+	* m4/locale-fr.m4 (gt_LOCALE_FR): On BeOS and Haiku, set LOCALE_FR=none.
+	* m4/locale-ja.m4 (gt_LOCALE_JA): On BeOS and Haiku, set LOCALE_JA-none.
+	* m4/locale-zh.m4 (gt_LOCALE_ZH_CN): On BeOS and Haiku, set
+	LOCALE_ZH_CN=none.
+
+2017-10-29  Bruno Haible  <br...@clisp.org>
+
 	strerror_r-posix: Fix behaviour and test failure on Haiku.
 	* lib/strerror_r.c (strerror_r): Don't assume that valid error numbers
 	are positive. Work around return value 0 instead of ERANGE on Haiku.
diff --git a/m4/locale-ar.m4 b/m4/locale-ar.m4
index 59b2827..0cf8397 100644
--- a/m4/locale-ar.m4
+++ b/m4/locale-ar.m4
@@ -1,4 +1,4 @@
-# locale-ar.m4 serial 6
+# locale-ar.m4 serial 7
 dnl Copyright (C) 2003, 2005-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -24,8 +24,14 @@ changequote(,)dnl
 struct tm t;
 char buf[16];
 int main () {
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if defined __BEOS__ || defined __HAIKU__
+  return 1;
+#else
   /* Check whether the given locale name is recognized by the system.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
   /* On native Windows, setlocale(category, "") looks at the system settings,
      not at the environment variables.  Also, when an encoding suffix such
      as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -33,26 +39,27 @@ int main () {
   if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
       || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
     return 1;
-#else
+# else
   if (setlocale (LC_ALL, "") == NULL) return 1;
-#endif
+# endif
   /* Check that nl_langinfo(CODESET) is nonempty and not "ASCII" or "646"
      and ends in "6". */
-#if HAVE_LANGINFO_CODESET
+# if HAVE_LANGINFO_CODESET
   {
     const char *cs = nl_langinfo (CODESET);
     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
         || cs[strlen (cs) - 1] != '6')
       return 1;
   }
-#endif
-#ifdef __CYGWIN__
+# endif
+# ifdef __CYGWIN__
   /* On Cygwin, avoid locale names without encoding suffix, because the
      locale_charset() function relies on the encoding suffix.  Note that
      LC_ALL is set on the command line.  */
   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
-#endif
+# endif
   return 0;
+#endif
 }
 changequote([,])dnl
       ])])
diff --git a/m4/locale-fr.m4 b/m4/locale-fr.m4
index 93d3da7..d974b03 100644
--- a/m4/locale-fr.m4
+++ b/m4/locale-fr.m4
@@ -1,4 +1,4 @@
-# locale-fr.m4 serial 17
+# locale-fr.m4 serial 18
 dnl Copyright (C) 2003, 2005-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -24,8 +24,14 @@ changequote(,)dnl
 struct tm t;
 char buf[16];
 int main () {
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if defined __BEOS__ || defined __HAIKU__
+  return 1;
+#else
   /* Check whether the given locale name is recognized by the system.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
   /* On native Windows, setlocale(category, "") looks at the system settings,
      not at the environment variables.  Also, when an encoding suffix such
      as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -33,9 +39,9 @@ int main () {
   if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
       || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
     return 1;
-#else
+# else
   if (setlocale (LC_ALL, "") == NULL) return 1;
-#endif
+# endif
   /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
      On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -44,32 +50,33 @@ int main () {
      some unit tests fail.
      On MirBSD 10, when an unsupported locale is specified, setlocale()
      succeeds but then nl_langinfo(CODESET) is "UTF-8".  */
-#if HAVE_LANGINFO_CODESET
+# if HAVE_LANGINFO_CODESET
   {
     const char *cs = nl_langinfo (CODESET);
     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
         || strcmp (cs, "UTF-8") == 0)
       return 1;
   }
-#endif
-#ifdef __CYGWIN__
+# endif
+# ifdef __CYGWIN__
   /* On Cygwin, avoid locale names without encoding suffix, because the
      locale_charset() function relies on the encoding suffix.  Note that
      LC_ALL is set on the command line.  */
   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
-#endif
+# endif
   /* Check whether in the abbreviation of the second month, the second
      character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
      one byte long. This excludes the UTF-8 encoding.  */
   t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
   if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
-#if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy.  */
+# if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy.  */
   /* Check whether the decimal separator is a comma.
      On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
      are nl_langinfo(RADIXCHAR) are both ".".  */
   if (localeconv () ->decimal_point[0] != ',') return 1;
-#endif
+# endif
   return 0;
+#endif
 }
 changequote([,])dnl
       ])])
diff --git a/m4/locale-ja.m4 b/m4/locale-ja.m4
index c1d1154..48d18d6 100644
--- a/m4/locale-ja.m4
+++ b/m4/locale-ja.m4
@@ -1,4 +1,4 @@
-# locale-ja.m4 serial 12
+# locale-ja.m4 serial 13
 dnl Copyright (C) 2003, 2005-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,9 +25,14 @@ struct tm t;
 char buf[16];
 int main ()
 {
-  const char *p;
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if defined __BEOS__ || defined __HAIKU__
+  return 1;
+#else
   /* Check whether the given locale name is recognized by the system.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
   /* On native Windows, setlocale(category, "") looks at the system settings,
      not at the environment variables.  Also, when an encoding suffix such
      as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -35,9 +40,9 @@ int main ()
   if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
       || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
     return 1;
-#else
+# else
   if (setlocale (LC_ALL, "") == NULL) return 1;
-#endif
+# endif
   /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
      On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -46,32 +51,36 @@ int main ()
      some unit tests fail.
      On MirBSD 10, when an unsupported locale is specified, setlocale()
      succeeds but then nl_langinfo(CODESET) is "UTF-8".  */
-#if HAVE_LANGINFO_CODESET
+# if HAVE_LANGINFO_CODESET
   {
     const char *cs = nl_langinfo (CODESET);
     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
         || strcmp (cs, "UTF-8") == 0)
       return 1;
   }
-#endif
-#ifdef __CYGWIN__
+# endif
+# ifdef __CYGWIN__
   /* On Cygwin, avoid locale names without encoding suffix, because the
      locale_charset() function relies on the encoding suffix.  Note that
      LC_ALL is set on the command line.  */
   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
-#endif
+# endif
   /* Check whether MB_CUR_MAX is > 1.  This excludes the dysfunctional locales
      on Cygwin 1.5.x.  */
   if (MB_CUR_MAX == 1)
     return 1;
   /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
      This excludes the UTF-8 encoding (except on MirBSD).  */
-  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
-  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
-  for (p = buf; *p != '\0'; p++)
-    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
-      return 1;
+  {
+    const char *p;
+    t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+    if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+    for (p = buf; *p != '\0'; p++)
+      if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+        return 1;
+  }
   return 0;
+#endif
 }
 changequote([,])dnl
       ])])
diff --git a/m4/locale-zh.m4 b/m4/locale-zh.m4
index 1459418..5fb7f53 100644
--- a/m4/locale-zh.m4
+++ b/m4/locale-zh.m4
@@ -1,4 +1,4 @@
-# locale-zh.m4 serial 12
+# locale-zh.m4 serial 13
 dnl Copyright (C) 2003, 2005-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -26,9 +26,14 @@ struct tm t;
 char buf[16];
 int main ()
 {
-  const char *p;
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if defined __BEOS__ || defined __HAIKU__
+  return 1;
+#else
   /* Check whether the given locale name is recognized by the system.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
   /* On native Windows, setlocale(category, "") looks at the system settings,
      not at the environment variables.  Also, when an encoding suffix such
      as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -36,9 +41,9 @@ int main ()
   if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
       || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
     return 1;
-#else
+# else
   if (setlocale (LC_ALL, "") == NULL) return 1;
-#endif
+# endif
   /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
      On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -47,32 +52,36 @@ int main ()
      some unit tests fail.
      On MirBSD 10, when an unsupported locale is specified, setlocale()
      succeeds but then nl_langinfo(CODESET) is "UTF-8".  */
-#if HAVE_LANGINFO_CODESET
+# if HAVE_LANGINFO_CODESET
   {
     const char *cs = nl_langinfo (CODESET);
     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
         || strcmp (cs, "UTF-8") == 0)
       return 1;
   }
-#endif
-#ifdef __CYGWIN__
+# endif
+# ifdef __CYGWIN__
   /* On Cygwin, avoid locale names without encoding suffix, because the
      locale_charset() function relies on the encoding suffix.  Note that
      LC_ALL is set on the command line.  */
   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
-#endif
+# endif
   /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
      This excludes the UTF-8 encoding (except on MirBSD).  */
-  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
-  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
-  for (p = buf; *p != '\0'; p++)
-    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
-      return 1;
+  {
+    const char *p;
+    t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+    if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+    for (p = buf; *p != '\0'; p++)
+      if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+        return 1;
+  }
   /* Check whether a typical GB18030 multibyte sequence is recognized as a
      single wide character.  This excludes the GB2312 and GBK encodings.  */
   if (mblen ("\203\062\332\066", 5) != 4)
     return 1;
   return 0;
+#endif
 }
 changequote([,])dnl
       ])])
-- 
2.7.4

Reply via email to