1 /* Test of getting user name.
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible and Paul Eggert. */
24 #if !(defined _WIN32 && !defined __CYGWIN__)
29 #include <sys/types.h>
34 test_getlogin_result (const char *buf
, int err
)
40 /* This can happen on GNU/Linux. */
41 fprintf (stderr
, "Skipping test: no entry in utmp file.\n");
45 /* It fails when stdin is not connected to a tty. */
47 || err
== EINVAL
/* seen on Linux/SPARC */
50 #if !defined __hpux /* On HP-UX 11.11 it fails anyway. */
51 ASSERT (! isatty (0));
53 fprintf (stderr
, "Skipping test: stdin is not a tty.\n");
57 /* Compare against the value from the environment. */
58 #if !(defined _WIN32 && !defined __CYGWIN__)
64 if (!isatty (STDIN_FILENO
))
66 fprintf (stderr
, "Skipping test: stdin is not a tty.\n");
70 ASSERT (fstat (STDIN_FILENO
, &stat_buf
) == 0);
75 fprintf (stderr
, "Skipping test: %s: no such user\n", buf
);
79 ASSERT (pwd
->pw_uid
== stat_buf
.st_uid
);
82 #if defined _WIN32 && !defined __CYGWIN__
83 /* Native Windows platform.
84 Note: This test would fail on Cygwin in an ssh session, because sshd
85 sets USERNAME=SYSTEM. */
87 const char *name
= getenv ("USERNAME");
88 if (name
!= NULL
&& name
[0] != '\0')
89 ASSERT (strcmp (buf
, name
) == 0);