/* Test of getting user name.
- Copyright (C) 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SIGNATURE_CHECK (getlogin_r, int, (char *, size_t));
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
/* Test with a large enough buffer. */
char buf[1024];
-
- ASSERT (getlogin_r (buf, sizeof (buf)) == 0);
+ int err;
+
+ 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;
+ }
/* Compare against the value from the environment. */
#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
size_t i;
for (i = 0; i <= n; i++)
- ASSERT (getlogin_r (smallbuf, i) == ERANGE);
+ {
+ err = getlogin_r (smallbuf, i);
+ if (i == 0)
+ ASSERT (err == ERANGE || err == EINVAL);
+ else
+ ASSERT (err == ERANGE);
+ }
}
/* Test with a huge buffer. */