X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=tests%2Ftest-getlogin_r.c;h=88c1f323148a164dee7e2498939d5b785d2f701d;hb=10302c2e3cd5a04446a4c9fb4ece0beceed30373;hp=f716ab952b9a7663d35fa0933f7b775415bbd29c;hpb=dd5823d49cf74819742b51ff48044ebe1adbd834;p=gnulib.git diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c index f716ab952..88c1f3231 100644 --- a/tests/test-getlogin_r.c +++ b/tests/test-getlogin_r.c @@ -1,5 +1,5 @@ /* Test of getting user name. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2013 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 @@ -24,6 +24,7 @@ SIGNATURE_CHECK (getlogin_r, int, (char *, size_t)); #include +#include #include #include @@ -34,8 +35,29 @@ main (void) { /* Test with a large enough buffer. */ char buf[1024]; + int err; - ASSERT (getlogin_r (buf, sizeof (buf)) == 0); + err = getlogin_r (buf, sizeof (buf)); + if (err != 0) + { + if (errno == ENOENT) + { + /* This can happen on GNU/Linux. */ + fprintf (stderr, "Skipping test: no entry in utmp file.\n"); + return 77; + } + + /* getlogin_r() fails when stdin is not connected to a tty. */ + ASSERT (err == ENOTTY + || errno == EINVAL /* seen on Linux/SPARC */ + || errno == ENXIO + ); +#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__) @@ -66,7 +88,21 @@ main (void) 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. */ + { + static char hugebuf[70000]; + + ASSERT (getlogin_r (hugebuf, sizeof (hugebuf)) == 0); + ASSERT (strcmp (hugebuf, buf) == 0); } return 0;