On HP-UX 11.11, when connected through ssh, getlogin() nevertheless returns an empty string and getlogin_r() fails, returning ENOTTY.
This is fixed in HP-UX 11.23. Let me document this issue and work around it in the unit test of getlogin_r(). 2010-12-20 Bruno Haible <br...@clisp.org> getlogin, getlogin_r: Document HP-UX 11.11 bugs. * doc/posix-functions/getlogin.texi: Document HP-UX 11.11 bug. * doc/posix-functions/getlogin_r.texi: Likewise. * tests/test-getlogin_r.c (main): Avoid test failure on HP-UX 11.11. --- doc/posix-functions/getlogin.texi.orig Mon Dec 20 12:30:12 2010 +++ doc/posix-functions/getlogin.texi Mon Dec 20 12:28:37 2010 @@ -15,4 +15,8 @@ Portability problems not fixed by Gnulib: @itemize +...@item +This function returns an empty string even when standard input is a tty +on some platforms: +HP-UX 11.11. @end itemize --- doc/posix-functions/getlogin_r.texi.orig Mon Dec 20 12:30:13 2010 +++ doc/posix-functions/getlogin_r.texi Mon Dec 20 12:28:38 2010 @@ -22,4 +22,7 @@ Portability problems not fixed by Gnulib: @itemize +...@item +This function fails even when standard input is a tty on some platforms: +HP-UX 11.11. @end itemize --- tests/test-getlogin_r.c.orig Mon Dec 20 12:30:13 2010 +++ tests/test-getlogin_r.c Mon Dec 20 12:28:37 2010 @@ -35,11 +35,16 @@ { /* Test with a large enough buffer. */ char buf[1024]; + int err; - if (getlogin_r (buf, sizeof (buf)) != 0) + err = getlogin_r (buf, sizeof (buf)); + if (err != 0) { /* getlogin_r() fails when stdin is not connected to a tty. */ + ASSERT (err == ENOTTY); +#if !defined __hpux /* On HP-UX 11.11 it fails anyway. */ ASSERT (! isatty (0)); +#endif fprintf (stderr, "Skipping test: stdin is not a tty.\n"); return 77; }