date and time created 82/11/07 19:06:08 by sam
[unix-history] / usr / src / lib / libc / gen / getlogin.c
/* @(#)getlogin.c 4.1 (Berkeley) %G% */
#include <utmp.h>
static char UTMP[] = "/etc/utmp";
static struct utmp ubuf;
char *
getlogin()
{
register me, uf;
register char *cp;
if( !(me = ttyslot()) )
return(0);
if( (uf = open( UTMP, 0 )) < 0 )
return(0);
lseek( uf, (long)(me*sizeof(ubuf)), 0 );
if (read(uf, (char *)&ubuf, sizeof(ubuf)) != sizeof(ubuf))
return(0);
close(uf);
ubuf.ut_name[sizeof (ubuf.ut_name)] = ' ';
for (cp=ubuf.ut_name; *cp++!=' ';)
;
*--cp = '\0';
return( ubuf.ut_name );
}