122122Smckusick /* 222122Smckusick * Copyright (c) 1984 Regents of the University of California. 322122Smckusick * All rights reserved. The Berkeley software License Agreement 422122Smckusick * specifies the terms and conditions for redistribution. 522122Smckusick */ 616277Ssam 7*26608Sdonn #if defined(LIBC_SCCS) && !defined(lint) 8*26608Sdonn static char sccsid[] = "@(#)ttyslot.c 5.2 (Berkeley) 03/09/86"; 9*26608Sdonn #endif LIBC_SCCS and not lint 1022122Smckusick 111995Swnj /* 121995Swnj * Return the number of the slot in the utmp file 131995Swnj * corresponding to the current user: try for file 0, 1, 2. 141995Swnj * Definition is the line number in the /etc/ttys file. 151995Swnj */ 1616422Sralph #include <ttyent.h> 171995Swnj 181995Swnj char *ttyname(); 191995Swnj char *rindex(); 201995Swnj 211995Swnj #define NULL 0 221995Swnj 231995Swnj ttyslot() 241995Swnj { 2516422Sralph register struct ttyent *ty; 261995Swnj register char *tp, *p; 2717880Sralph register s; 281995Swnj 2916277Ssam if ((tp = ttyname(0)) == NULL && 3016277Ssam (tp = ttyname(1)) == NULL && 3116277Ssam (tp = ttyname(2)) == NULL) 321995Swnj return(0); 331995Swnj if ((p = rindex(tp, '/')) == NULL) 341995Swnj p = tp; 351995Swnj else 361995Swnj p++; 3716422Sralph setttyent(); 381995Swnj s = 0; 3916422Sralph while ((ty = getttyent()) != NULL) { 401995Swnj s++; 4116422Sralph if (strcmp(ty->ty_name, p) == 0) { 4216422Sralph endttyent(); 4316277Ssam return (s); 441995Swnj } 451995Swnj } 4616422Sralph endttyent(); 4716277Ssam return (0); 481995Swnj } 49