Annotation of coherent/b/lib/libc/gen/getlogin.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Coherent I/O Library.
                      3:  * Get login name from the utmp file.
                      4:  */
                      5: 
                      6: #include <stdio.h>
                      7: #include <utmp.h>
                      8: 
                      9: char   *ttyname();
                     10: 
                     11: char *
                     12: getlogin()
                     13: {
                     14:        register struct utmp *up;
                     15:        register int n;
                     16:        register char *tname;
                     17:        register int ufd;
                     18:        char iobuf[BUFSIZ+1];
                     19:        static char uname[DIRSIZ];
                     20: 
                     21:        if ((ufd = open("/etc/utmp", 0))>=0
                     22:            && (tname = ttyname(fileno(stderr)))!=NULL) {
                     23:                tname += 5;                     /* Skip over "/dev/" */
                     24:                while ((n = read(ufd, iobuf, BUFSIZ)) > 0)
                     25:                        for (up = iobuf; up < &iobuf[n]; up++)
                     26:                                if (strncmp(up->ut_line, tname, 8) == 0) {
                     27:                                        close(ufd);
                     28:                                        strncpy(uname, up->ut_name, DIRSIZ);
                     29:                                        return (uname);
                     30:                                }
                     31:                close(ufd);
                     32:        }
                     33:        return (NULL);
                     34: }

unix.superglobalmegacorp.com

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