SCCS-vsn: lib/libc/gen/ttyslot.c 4.3
SCCS-vsn: lib/libc/gen/getlogin.c 4.3
-/* getlogin.c 4.2 82/11/14 */
+/* getlogin.c 4.3 84/04/27 */
-/* @(#)ttyslot.c 4.2 (Berkeley) %G% */
+/* @(#)ttyslot.c 4.3 (Berkeley) %G% */
/*
* Return the number of the slot in the utmp file
* corresponding to the current user: try for file 0, 1, 2.
* Definition is the line number in the /etc/ttys file.
*/
/*
* Return the number of the slot in the utmp file
* corresponding to the current user: try for file 0, 1, 2.
* Definition is the line number in the /etc/ttys file.
*/
-static char ttys[] = "/etc/ttys";
#define NULL 0
ttyslot()
{
#define NULL 0
ttyslot()
{
+ register struct ttyent *ty;
register char *tp, *p;
register s, tf;
register char *tp, *p;
register s, tf;
- if ((tf = open(ttys, O_RDONLY)) < 0)
- return (0);
- while (tp = getttys(tf)) {
+ while ((ty = getttyent()) != NULL) {
- if (strcmp(p, tp) == 0) {
- close(tf);
+ if (strcmp(ty->ty_name, p) == 0) {
+ endttyent();
-
-#define BUFSIZ 1024
-
-static char *
-getttys(f)
-{
- static char buf[BUFSIZ + 1], *next = &buf[BUFSIZ + 1];
- register char *lp;
- char *start;
-
- for (;;) {
- if (next >= &buf[BUFSIZ]) {
- int n = read(f, buf, BUFSIZ);
-
- if (n <= 0)
- return (NULL);
- buf[n] = '\0';
- next = &buf[0];
- }
- for (lp = next; *lp && *lp != '\n'; lp++)
- ;
- if (*lp == '\n') {
- *lp++ = '\0';
- start = next;
- next = lp;
- return (start + 2);
- }
- lseek(f, next - lp, L_INCR);
- next = lp;
- }
-}