From: Bruno Haible Date: Thu, 23 May 2024 17:13:16 +0000 (+0200) Subject: sethostname tests: Avoid test failure on Cygwin. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a62b0ffd5336879996fbac59d97c31457c53340d;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 1ebd9c30e0..ea0e3fa766 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-05-23 Bruno Haible + + 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 access, euidaccess tests: Avoid test failures on Cygwin. diff --git a/doc/glibc-functions/sethostname.texi b/doc/glibc-functions/sethostname.texi index 1aff926cd4..cef0edf268 100644 --- a/doc/glibc-functions/sethostname.texi +++ b/doc/glibc-functions/sethostname.texi @@ -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 diff --git a/tests/test-sethostname2.c b/tests/test-sethostname2.c index 33d7da76de..25a3ae1857 100644 --- a/tests/test-sethostname2.c +++ b/tests/test-sethostname2.c @@ -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: + */ +#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);