home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / libc / gen / getlogin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  456 b   |  26 lines

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