Annotation of 42BSD/lib/libc/gen/getlogin.c, revision 1.1

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

unix.superglobalmegacorp.com

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