From 8a0bfb58be36d76250cb14a97611737f07468dd0 Mon Sep 17 00:00:00 2001 From: Oliver Lehmann Date: Thu, 22 Mar 1990 14:06:21 +0000 Subject: [PATCH] add LCC - a better C-Compiler for WEGA --- WEGA/contrib/lcc/lib/libc/port/gen/ttyslot.c | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 WEGA/contrib/lcc/lib/libc/port/gen/ttyslot.c diff --git a/WEGA/contrib/lcc/lib/libc/port/gen/ttyslot.c b/WEGA/contrib/lcc/lib/libc/port/gen/ttyslot.c new file mode 100644 index 0000000..f83c09b --- /dev/null +++ b/WEGA/contrib/lcc/lib/libc/port/gen/ttyslot.c @@ -0,0 +1,42 @@ +/* + * Return the number of the slot in the utmp file + * corresponding to the current user: try for file 0, 1, 2. + * Returns -1 if slot not found. + */ +#include +#include +#define NULL 0 + +extern char *ttyname(), *strrchr(); +extern int strncmp(), open(), read(), close(); + +int +ttyslot() +{ + struct utmp ubuf; + register char *tp, *p; + register int s, fd; + + if((tp=ttyname(0)) == NULL && (tp=ttyname(1)) == NULL && + (tp=ttyname(2)) == NULL) + return(-1); + + if((p=strrchr(tp, '/')) == NULL) + p = tp; + else + p++; + + if((fd=open(UTMP_FILE, 0)) < 0) + return(-1); + s = 0; + while(read(fd, (char*)&ubuf, sizeof(ubuf)) == sizeof(ubuf)) { + if (strncmp(p, ubuf.ut_line, sizeof(ubuf.ut_line)) == 0){ + + (void) close(fd); + return(s); + } + s++; + } + (void) close(fd); + return(-1); +}