Commit | Line | Data |
---|---|---|
2ce81398 | 1 | #if defined(LIBC_SCCS) && !defined(lint) |
9a92b984 | 2 | static char sccsid[] = "@(#)getlogin.c 5.3 (Berkeley) %G%"; |
2ce81398 | 3 | #endif LIBC_SCCS and not lint |
056d5bbd | 4 | |
d144c87e SL |
5 | #include <utmp.h> |
6 | ||
056d5bbd SL |
7 | static char UTMP[] = "/etc/utmp"; |
8 | static struct utmp ubuf; | |
d144c87e SL |
9 | |
10 | char * | |
11 | getlogin() | |
12 | { | |
056d5bbd | 13 | register int me, uf; |
d144c87e SL |
14 | register char *cp; |
15 | ||
056d5bbd | 16 | if (!(me = ttyslot())) |
d144c87e | 17 | return(0); |
056d5bbd SL |
18 | if ((uf = open(UTMP, 0)) < 0) |
19 | return (0); | |
20 | lseek (uf, (long)(me*sizeof(ubuf)), 0); | |
21 | if (read(uf, (char *)&ubuf, sizeof (ubuf)) != sizeof (ubuf)) { | |
22 | close(uf); | |
23 | return (0); | |
24 | } | |
d144c87e | 25 | close(uf); |
8b87fcc2 JL |
26 | if (ubuf.ut_name[0] == '\0') |
27 | return (0); | |
d144c87e | 28 | ubuf.ut_name[sizeof (ubuf.ut_name)] = ' '; |
056d5bbd | 29 | for (cp = ubuf.ut_name; *cp++ != ' '; ) |
d144c87e SL |
30 | ; |
31 | *--cp = '\0'; | |
056d5bbd | 32 | return (ubuf.ut_name); |
d144c87e | 33 | } |