I've been playing around with this further, and have some new findings,
and a revised patch.

* Turns out the problem with -lposix yielding "Floating point exception"
  is that you're not supposed to link to that library directly; instead,
  you specify "cc -posix". Akin to -lpthread vs. -pthread.

  With this, a *lot* more things are working now. In fact, the only
  breakage still in gllib is strcoll(), due to this platform's odd
  three-
  argument form of it. (Could you point me to where this sort of quirk
  should be worked around?)

* I've added a definition of EILSEQ to lib/errno.in.h; does that
  look right?

  The libiconv folks may need to be pinged about this change, as I
  noticed that they check for EILSEQ too, and if it's missing, #define
  it to ENOENT.

* Changed all uses of __STRICT_ANSI__ to "defined __STRICT_ANSI__". This
  is how both NeXT and current glibc headers use the symbol; IMO, this
  is really how it should be done.

  A bit of clarification: There is actually no difference in how this
  ancient version of GCC handles cpp symbols versus newer ones. An
  undefined cpp symbol is silently replaced with 0 (thus none of the
  missing HAVE_* symbols broke).

  An empty cpp symbol, however, will be substituted as-is, which can
  lead to cpp expression breakage. This is as true today as in 1992.
  __STRICT_ANSI__ is usually #defined by GCC, and when it does so, it's
  nice enough to set a value of 1. You run into trouble, however, if
  some header somewhere defines this symbol (or some other symbol) to an
  empty value. That's what was happening here. (And this is hardly
  limited to NeXT; look in the current X11/Xarch.h header.)

  (Ideally, all of these cpp symbols should be tested with #ifdef / #if
  defined(). Not only does that make expressions robust to this kind of
  breakage, it quashes warnings from -Wundef, and it avoids the
  somewhat awkward nature of the undef-versus-1 duality. It makes more
  sense to say your coffee cup is either empty or full, rather than
  empty or hot!)

* Tacked on "&& !defined __NeXT__" in lib/stdio.in.h. Easier than adding
  a separate test for asm-label functionality, anyway.

* New and improved absolute-header matching code.

* Make use of setrlimit() if available to escape from the infinite
  frexp() trap.

* Check the program return code when comparing strerror() and perror().

* I missed that the 50-day sleep is necessary to check for a Cygwin bug.
  So I tweaked the test so that this long sleep is only used on Cygwin
  (where, presumably, alarm() has always worked correctly), and all
  other systems use 15 seconds.

* Many of the tests still fail to build, not because the functions for
  them are not available, but because said declarations for these
  functions either disappear with -posix->_POSIX_SOURCE->__STRICT_ANSI__
  (which we can't do anything about), or don't exist in any standard
  headers at all.

  Math functions tend to fall in the former category, and various
  syscalls in the latter. (Seriously; you look at the man pages for e.g.
  fsync() or readlink(), and the synopsis has no #includes.)

  Providing the declarations should get all of these going again. Is
  there any precedent for doing this in gnulib?


Patch against current git master is attached.


--Daniel


-- 
Daniel Richard G. || sk...@iskunk.org
My ASCII-art .sig got a bad case of Times New Roman.
diff --git a/lib/errno.in.h b/lib/errno.in.h
index 0bf5792..eafda21 100644
--- a/lib/errno.in.h
+++ b/lib/errno.in.h
@@ -172,6 +172,11 @@
 #  define GNULIB_defined_ECANCELED 1
 # endif
 
+# ifndef EILSEQ
+#  define EILSEQ 2013
+#  define GNULIB_defined_EILSEQ 1
+# endif
+
 
 #endif /* _@GUARD_PREFIX@_ERRNO_H */
 #endif /* _@GUARD_PREFIX@_ERRNO_H */
diff --git a/lib/gettext.h b/lib/gettext.h
index 65777e6..1ddd68a 100644
--- a/lib/gettext.h
+++ b/lib/gettext.h
@@ -185,7 +185,7 @@ npgettext_aux (const char *domain,
 #include <string.h>
 
 #define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
-  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
+  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
    /* || __STDC_VERSION__ >= 199901L */ )
 
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
diff --git a/lib/math.in.h b/lib/math.in.h
index d3b4839..c92703f 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -1188,7 +1188,7 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
 _GL_EXTERN_C int gl_signbitf (float arg);
 _GL_EXTERN_C int gl_signbitd (double arg);
 _GL_EXTERN_C int gl_signbitl (long double arg);
-#  if __GNUC__ >= 2 && !__STRICT_ANSI__
+#  if __GNUC__ >= 2 && !defined __STRICT_ANSI__
 #   define _GL_NUM_UINT_WORDS(type) \
       ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
diff --git a/lib/regex.h b/lib/regex.h
index 27b2226..ea781e1 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -644,7 +644,7 @@ extern int re_exec (const char *);
 #ifndef _Restrict_arr_
 # if ((199901L <= __STDC_VERSION__					\
        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))	\
-	   && !__STRICT_ANSI__))					\
+	   && !defined __STRICT_ANSI__))				\
       && !defined __GNUG__)
 #  define _Restrict_arr_ _Restrict_
 # else
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index d7413b0..20cc833 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -334,7 +334,7 @@ typedef struct
     Idx idx;			/* for BACK_REF */
     re_context_type ctx_type;	/* for ANCHOR */
   } opr;
-#if __GNUC__ >= 2 && !__STRICT_ANSI__
+#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
   re_token_type_t type : 8;
 #else
   re_token_type_t type;
diff --git a/lib/regexec.c b/lib/regexec.c
index 5ad438f..7776f9b 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -3985,7 +3985,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
 # endif /* _LIBC */
 	{
 	  /* match with range expression?  */
-#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && __STRICT_ANSI__)
+#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && defined __STRICT_ANSI__)
 	  wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
 #else
 	  wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
index 3c31fd0..e326022 100644
--- a/lib/spawn.in.h
+++ b/lib/spawn.in.h
@@ -63,7 +63,7 @@
 #ifndef _Restrict_arr_
 # if ((199901L <= __STDC_VERSION__                                      \
        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))     \
-           && !__STRICT_ANSI__))                                        \
+           && !defined __STRICT_ANSI__))                                \
       && !defined __GNUG__)
 #  define _Restrict_arr_ _Restrict_
 # else
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index ebbf801..35c45e1 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -833,7 +833,7 @@ _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
      || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
-#  if defined __GNUC__
+#  if defined __GNUC__ && !defined __NeXT__
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 /* Don't break __attribute__((format(printf,M,N))).  */
 #    define printf __printf__
diff --git a/m4/absolute-header.m4 b/m4/absolute-header.m4
index b7276a3..e5ffbd0 100644
--- a/m4/absolute-header.m4
+++ b/m4/absolute-header.m4
@@ -81,7 +81,10 @@ changequote(,)
       gl_dirsep_regex='/'
       ;;
   esac
-  gl_absolute_header_sed='\|'"${gl_dirsep_regex}"'$1|{
+  dnl Older seds don't support '\|blah|{...}'
+  gl_absolute_header_sed='s,\([/.]\),\\\1,g'
+  gl_absolute_header_match=`printf '%s\n' "${gl_dirsep_regex}"'$1' | sed "$gl_absolute_header_sed"`
+  gl_absolute_header_sed="/${gl_absolute_header_match}/"'{
       s|.*"\(.*'"${gl_dirsep_regex}"'$1\)".*|\1|
       s|^/[^/]|//&|
       p
diff --git a/m4/frexp.m4 b/m4/frexp.m4
index f2048f3..fe76022 100644
--- a/m4/frexp.m4
+++ b/m4/frexp.m4
@@ -93,6 +93,7 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CHECK_FUNCS_ONCE([setrlimit])
   AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
     [
       AC_RUN_IFELSE(
@@ -100,6 +101,11 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 #include <float.h>
 #include <math.h>
 #include <string.h>
+#ifdef HAVE_SETRLIMIT
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#endif
 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
    ICC 10.0 has a bug when optimizing the expression -zero.
    The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
@@ -120,6 +126,13 @@ int main()
   int i;
   volatile double x;
   double zero = 0.0;
+#if defined HAVE_SETRLIMIT && defined RLIMIT_CPU
+  /* On some systems, calling frexp() with an infinite value causes the
+     function to spin forever.  Five seconds of CPU should be enough.  */
+  struct rlimit rl;
+  rl.rlim_cur = rl.rlim_max = 5;
+  setrlimit(RLIMIT_CPU, &rl);
+#endif
   /* Test on denormalized numbers.  */
   for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
     ;
diff --git a/m4/include_next.m4 b/m4/include_next.m4
index d5230ce..638f936 100644
--- a/m4/include_next.m4
+++ b/m4/include_next.m4
@@ -223,7 +223,11 @@ changequote(,)
                    ;;
                esac
 changequote([,])
-               gl_absolute_header_sed='\|'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[|{
+               dnl Older seds don't support '\|blah|{...}'
+               gl_absolute_header_sed='s,\([/.]\),\\\1,g'
+               gl_absolute_header_match=`printf '%s\n' "${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[' |
+                                         sed "$gl_absolute_header_sed"`
+               gl_absolute_header_sed="/${gl_absolute_header_match}/"'{
                    s|.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*|\1|
 changequote(,)dnl
                    s|^/[^/]|//&|
diff --git a/m4/perror.m4 b/m4/perror.m4
index 8c28d44..68eee6e 100644
--- a/m4/perror.m4
+++ b/m4/perror.m4
@@ -38,7 +38,8 @@ AC_DEFUN([gl_FUNC_PERROR],
                 perror ("");
               ]])],
            [CONFTEST_OUTPUT=1 ./conftest$EXEEXT >conftest.txt1 2>conftest.txt2
-            if cmp conftest.txt1 conftest.txt2 >/dev/null; then
+            result=$?
+            if test $result = 0 && cmp conftest.txt1 conftest.txt2 >/dev/null; then
               gl_cv_func_perror_works=yes
             else
               gl_cv_func_perror_works=no
diff --git a/m4/sleep.m4 b/m4/sleep.m4
index 74362e4..fdc1af8 100644
--- a/m4/sleep.m4
+++ b/m4/sleep.m4
@@ -17,7 +17,6 @@ AC_DEFUN([gl_FUNC_SLEEP],
   if test $ac_cv_have_decl_sleep != yes; then
     HAVE_SLEEP=0
   else
-    dnl Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days.
     AC_CACHE_CHECK([for working sleep], [gl_cv_func_sleep_works],
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
 #include <errno.h>
@@ -32,14 +31,20 @@ handle_alarm (int sig)
 ]], [[
     /* Failure to compile this test due to missing alarm is okay,
        since all such platforms (mingw) also lack sleep.  */
-    unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days.  */
+#ifdef __CYGWIN__
+    /* Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days.  */
+    unsigned int period = 50 * 24 * 60 * 60;
+#else
+    /* In case alarm() doesn't work, don't wait too long.  */
+    unsigned int period = 15;
+#endif
     unsigned int remaining;
     signal (SIGALRM, handle_alarm);
     alarm (1);
-    remaining = sleep (pentecost);
-    if (remaining > pentecost)
+    remaining = sleep (period);
+    if (remaining > period)
       return 3;
-    if (remaining <= pentecost - 10)
+    if (remaining <= period - 10)
       return 4;
     return 0;
     ]])],
diff --git a/tests/test-printf-posix.c b/tests/test-printf-posix.c
index 9337854..0bc3def 100644
--- a/tests/test-printf-posix.c
+++ b/tests/test-printf-posix.c
@@ -39,7 +39,7 @@ main (int argc, char *argv[])
 }
 
 /* Test whether __attribute__ (__format__ (...)) still works.  */
-#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !__STRICT_ANSI__
+#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !defined __STRICT_ANSI__
 extern int func1 (char *, size_t, const char *, ...)
      __attribute__ ((__format__ (__printf__, 3, 4)));
 extern int func2 (char *, size_t, const char *, ...)

Reply via email to