File:  [MW Coherent from dump] / coherent / b / lib / libc / gen / getlogin.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Coherent I/O Library.
 * Get login name from the utmp file.
 */

#include <stdio.h>
#include <utmp.h>

char	*ttyname();

char *
getlogin()
{
	register struct utmp *up;
	register int n;
	register char *tname;
	register int ufd;
	char iobuf[BUFSIZ+1];
	static char uname[DIRSIZ];

	if ((ufd = open("/etc/utmp", 0))>=0
	    && (tname = ttyname(fileno(stderr)))!=NULL) {
		tname += 5;			/* Skip over "/dev/" */
		while ((n = read(ufd, iobuf, BUFSIZ)) > 0)
			for (up = iobuf; up < &iobuf[n]; up++)
				if (strncmp(up->ut_line, tname, 8) == 0) {
					close(ufd);
					strncpy(uname, up->ut_name, DIRSIZ);
					return (uname);
				}
		close(ufd);
	}
	return (NULL);
}

unix.superglobalmegacorp.com

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