xref: /csrg-svn/lib/libc/gen/getlogin.c (revision 9109)
1 /*	@(#)getlogin.c	4.1 (Berkeley) 11/07/82	*/
2 #include <utmp.h>
3 
4 static	char	UTMP[]	= "/etc/utmp";
5 static	struct	utmp ubuf;
6 
7 char *
8 getlogin()
9 {
10 	register me, uf;
11 	register char *cp;
12 
13 	if( !(me = ttyslot()) )
14 		return(0);
15 	if( (uf = open( UTMP, 0 )) < 0 )
16 		return(0);
17 	lseek( uf, (long)(me*sizeof(ubuf)), 0 );
18 	if (read(uf, (char *)&ubuf, sizeof(ubuf)) != sizeof(ubuf))
19 		return(0);
20 	close(uf);
21 	ubuf.ut_name[sizeof (ubuf.ut_name)] = ' ';
22 	for (cp=ubuf.ut_name; *cp++!=' ';)
23 		;
24 	*--cp = '\0';
25 	return( ubuf.ut_name );
26 }
27