Annotation of 43BSD/lib/libc/gen/getlogin.c, revision 1.1.1.1

1.1       root        1: #if defined(LIBC_SCCS) && !defined(lint)
                      2: static char sccsid[] = "@(#)getlogin.c 5.3 (Berkeley) 5/9/86";
                      3: #endif LIBC_SCCS and not lint
                      4: 
                      5: #include <utmp.h>
                      6: 
                      7: static char UTMP[]     = "/etc/utmp";
                      8: static struct utmp ubuf;
                      9: 
                     10: char *
                     11: getlogin()
                     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: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.