Last change
on this file since 444 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
904 bytes
|
Line | |
---|
1 | #ifndef _NO_GETLOGIN |
---|
2 | |
---|
3 | #include <string.h> |
---|
4 | #include <unistd.h> |
---|
5 | #include <sys/types.h> |
---|
6 | #include <utmp.h> |
---|
7 | #include <fcntl.h> |
---|
8 | #include <_syslist.h> |
---|
9 | |
---|
10 | char * |
---|
11 | getlogin () |
---|
12 | { |
---|
13 | int utmp_fd; |
---|
14 | struct utmp utmp_buf; |
---|
15 | static char buf[10]; |
---|
16 | extern char *ttyname (); |
---|
17 | char *tty; |
---|
18 | |
---|
19 | if (((tty = ttyname (0)) == 0) |
---|
20 | || ((tty = ttyname (1)) == 0) |
---|
21 | || ((tty = ttyname (2)) == 0)) |
---|
22 | return 0; |
---|
23 | |
---|
24 | if ((utmp_fd = open (UTMP_FILE, O_RDONLY)) == -1) |
---|
25 | return 0; |
---|
26 | |
---|
27 | if (!strncmp (tty, "/dev/", 5)) |
---|
28 | tty += 5; |
---|
29 | |
---|
30 | while (read (utmp_fd, &utmp_buf, sizeof (utmp_buf)) == sizeof (utmp_buf)) |
---|
31 | { |
---|
32 | if (!strncmp (tty, utmp_buf.ut_line, sizeof (utmp_buf.ut_line)) |
---|
33 | && utmp_buf.ut_type == USER_PROCESS) |
---|
34 | { |
---|
35 | close (utmp_fd); |
---|
36 | memset (buf, 0, sizeof (buf)); |
---|
37 | strncpy (buf, utmp_buf.ut_user, sizeof (utmp_buf.ut_user)); |
---|
38 | return buf; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | close (utmp_fd); |
---|
43 | return 0; |
---|
44 | } |
---|
45 | #endif /* !_NO_GETLOGIN */ |
---|
Note: See
TracBrowser
for help on using the repository browser.