ttyslot.c revision 90041
1254721Semaste/*
2254721Semaste * Copyright (c) 1988, 1993
3254721Semaste *	The Regents of the University of California.  All rights reserved.
4254721Semaste *
5254721Semaste * Redistribution and use in source and binary forms, with or without
6254721Semaste * modification, are permitted provided that the following conditions
7254721Semaste * are met:
8254721Semaste * 1. Redistributions of source code must retain the above copyright
9254721Semaste *    notice, this list of conditions and the following disclaimer.
10254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
11254721Semaste *    notice, this list of conditions and the following disclaimer in the
12254721Semaste *    documentation and/or other materials provided with the distribution.
13254721Semaste * 3. All advertising materials mentioning features or use of this software
14254721Semaste *    must display the following acknowledgement:
15254721Semaste *	This product includes software developed by the University of
16254721Semaste *	California, Berkeley and its contributors.
17254721Semaste * 4. Neither the name of the University nor the names of its contributors
18254721Semaste *    may be used to endorse or promote products derived from this software
19254721Semaste *    without specific prior written permission.
20254721Semaste *
21254721Semaste * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31254721Semaste * SUCH DAMAGE.
32254721Semaste */
33254721Semaste
34254721Semaste#if defined(LIBC_SCCS) && !defined(lint)
35254721Semastestatic char sccsid[] = "@(#)ttyslot.c	8.1 (Berkeley) 6/4/93";
36254721Semaste#endif /* LIBC_SCCS and not lint */
37254721Semaste#include <sys/cdefs.h>
38254721Semaste__FBSDID("$FreeBSD: head/lib/libc/gen/ttyslot.c 90041 2002-02-01 01:08:48Z obrien $");
39254721Semaste
40254721Semaste#include <ttyent.h>
41254721Semaste#include <stdio.h>
42254721Semaste#include <string.h>
43254721Semaste#include <unistd.h>
44254721Semaste
45254721Semasteint
46254721Semastettyslot()
47254721Semaste{
48254721Semaste	struct ttyent *ttyp;
49254721Semaste	int slot;
50254721Semaste	char *p;
51254721Semaste	int cnt;
52254721Semaste	char *name;
53254721Semaste
54254721Semaste	setttyent();
55254721Semaste	for (cnt = 0; cnt < 3; ++cnt)
56254721Semaste		if ( (name = ttyname(cnt)) ) {
57254721Semaste			if ( (p = rindex(name, '/')) )
58254721Semaste				++p;
59254721Semaste			else
60254721Semaste				p = name;
61254721Semaste			for (slot = 1; (ttyp = getttyent()); ++slot)
62254721Semaste				if (!strcmp(ttyp->ty_name, p)) {
63254721Semaste					endttyent();
64254721Semaste					return(slot);
65254721Semaste				}
66254721Semaste			break;
67254721Semaste		}
68254721Semaste	endttyent();
69254721Semaste	return(0);
70254721Semaste}
71254721Semaste