This source file includes following definitions.
- test_getlogin_result
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #if !(defined _WIN32 && !defined __CYGWIN__)
25 # include <pwd.h>
26 #endif
27
28 #include <sys/stat.h>
29 #include <sys/types.h>
30
31 #include "macros.h"
32
33 static void
34 test_getlogin_result (const char *buf, int err)
35 {
36 if (err != 0)
37 {
38 if (err == ENOENT)
39 {
40
41 fprintf (stderr, "Skipping test: no entry in utmp file.\n");
42 exit (77);
43 }
44
45
46 ASSERT (err == ENOTTY
47 || err == EINVAL
48 || err == ENXIO
49 );
50 #if !defined __hpux
51 ASSERT (! isatty (0));
52 #endif
53 fprintf (stderr, "Skipping test: stdin is not a tty.\n");
54 exit (77);
55 }
56
57
58 #if !(defined _WIN32 && !defined __CYGWIN__)
59
60 {
61 struct stat stat_buf;
62 struct passwd *pwd;
63
64 if (!isatty (STDIN_FILENO))
65 {
66 fprintf (stderr, "Skipping test: stdin is not a tty.\n");
67 exit (77);
68 }
69
70 ASSERT (fstat (STDIN_FILENO, &stat_buf) == 0);
71
72 pwd = getpwnam (buf);
73 if (! pwd)
74 {
75 fprintf (stderr, "Skipping test: %s: no such user\n", buf);
76 exit (77);
77 }
78
79 ASSERT (pwd->pw_uid == stat_buf.st_uid);
80 }
81 #endif
82 #if defined _WIN32 && !defined __CYGWIN__
83
84
85
86 {
87 const char *name = getenv ("USERNAME");
88 if (name != NULL && name[0] != '\0')
89 ASSERT (strcmp (buf, name) == 0);
90 }
91 #endif
92 }