59 is unused; 61 is ECONNREFUSED not EREFUSED; add Berkeley header
[unix-history] / usr / src / lib / libc / gen / getlogin.c
... / ...
CommitLineData
1#if defined(LIBC_SCCS) && !defined(lint)
2static char sccsid[] = "@(#)getlogin.c 5.3 (Berkeley) %G%";
3#endif LIBC_SCCS and not lint
4
5#include <utmp.h>
6
7static char UTMP[] = "/etc/utmp";
8static struct utmp ubuf;
9
10char *
11getlogin()
12{
13 register int me, uf;
14 register char *cp;
15
16 if (!(me = ttyslot()))
17 return(0);
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 }
25 close(uf);
26 if (ubuf.ut_name[0] == '\0')
27 return (0);
28 ubuf.ut_name[sizeof (ubuf.ut_name)] = ' ';
29 for (cp = ubuf.ut_name; *cp++ != ' '; )
30 ;
31 *--cp = '\0';
32 return (ubuf.ut_name);
33}