]> Savannah Git Hosting - gnulib.git/commitdiff
sethostname tests: Avoid test failure on Cygwin.
authorBruno Haible <bruno@clisp.org>
Thu, 23 May 2024 17:13:16 +0000 (19:13 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 23 May 2024 17:13:16 +0000 (19:13 +0200)
* tests/test-sethostname2.c (main): On Cygwin, skip the "too long
hostname" test.
* doc/glibc-functions/sethostname.texi: Mention the Cygwin problem.

ChangeLog
doc/glibc-functions/sethostname.texi
tests/test-sethostname2.c

index 1ebd9c30e0c037e87b0e32cb1dbd3d0d8dc5eb8a..ea0e3fa76623dff7fed0aeffd46c7a150dc5639f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-05-23  Bruno Haible  <bruno@clisp.org>
+
+       sethostname tests: Avoid test failure on Cygwin.
+       * tests/test-sethostname2.c (main): On Cygwin, skip the "too long
+       hostname" test.
+       * doc/glibc-functions/sethostname.texi: Mention the Cygwin problem.
+
 2024-05-23  Bruno Haible  <bruno@clisp.org>
 
        access, euidaccess tests: Avoid test failures on Cygwin.
index 1aff926cd4af2d177d0f0b2ed01b64b480d17313..cef0edf268a6a2153d4684161f5fee2549483d39 100644 (file)
@@ -40,4 +40,8 @@ Solaris 11 2010-11.
 The second parameter is @code{int} instead of @code{size_t}
 on some platforms:
 macOS 12.5, FreeBSD 14.0, MidnightBSD 3.0, Solaris 11 2010-11, Solaris 11 OpenIndiana, Solaris 11 OmniOS.
+@item
+This function does not reject a too long host name on some platforms:
+@c https://cygwin.com/pipermail/cygwin/2024-May/255986.html
+Cygwin 3.5.3.
 @end itemize
index 33d7da76dec5c3644a5c3224208aee66644b107a..25a3ae1857cf5083bfe9385069c754455d588ce0 100644 (file)
@@ -45,7 +45,6 @@ main (int argc, _GL_UNUSED char *argv[])
 {
   char origname[HOST_NAME_MAX];
   char newname[HOST_NAME_MAX];
-  char longname[HOST_NAME_MAX + 2];
   int rcs, i;
 
   /* skip the tests if we don't have root privilege.  this does not
@@ -108,23 +107,31 @@ main (int argc, _GL_UNUSED char *argv[])
 #endif
     }
 
-  /* glibc does allow setting a zero length name, so the lower bound
-     needs no test. validate that we are constrained by
-     HOST_NAME_MAX */
-  for (i = 0; i < (HOST_NAME_MAX + 1); i++)
-    longname[i] = 'a';
-
-  longname[i] = '\0';
-
-  rcs = sethostname (longname, (HOST_NAME_MAX + 1));
-
-  if (rcs != -1)
-    {
-      /* attempt to restore the original name. */
-      ASSERT (sethostname (origname, strlen (origname)) == 0);
-      fprintf (stderr, "setting a too long hostname succeeded.\n");
-      return 1;
-    }
+  /* Known Cygwin bug:
+     <https://cygwin.com/pipermail/cygwin/2024-May/255986.html>  */
+#if !defined __CYGWIN__
+  {
+    char longname[HOST_NAME_MAX + 2];
+
+    /* glibc does allow setting a zero length name, so the lower bound
+       needs no test. validate that we are constrained by
+       HOST_NAME_MAX */
+    for (i = 0; i < (HOST_NAME_MAX + 1); i++)
+      longname[i] = 'a';
+
+    longname[i] = '\0';
+
+    rcs = sethostname (longname, (HOST_NAME_MAX + 1));
+
+    if (rcs != -1)
+      {
+        /* attempt to restore the original name. */
+        ASSERT (sethostname (origname, strlen (origname)) == 0);
+        fprintf (stderr, "setting a too long hostname succeeded.\n");
+        return 1;
+      }
+  }
+#endif
 
   /* restore the original name. */
   ASSERT (sethostname (origname, strlen (origname)) == 0);