Getting tty name without using ttyname(3)

John F. Haugh II jfh at rpp386.cactus.org
Fri Feb 16 17:12:38 AEST 1990


In article <15137:00:09:24 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
>In article <673 at compel.UUCP> her at compel.UUCP (Helge Egelund Rasmussen) writes:
>> I need to write a replacement for the SYSV release 3 ttyname(3) function.
>
>ttyname() takes a file descriptor argument and (as you observed) searches
>through /dev for a tty (or just any file? I haven't checked) referencing
>the same inode. If you have a lot of non-tty entries in /dev, you could
>write a much faster version that only looks at files beginning with tty.
>Of course, to avoid confusion you shouldn't call this ttyname().
>
>Use directory(3), stat(2). (The whole thing is a kludge.)

How about using DBM?  Write a program which takes filenames as arguments
and saves the names away using the device-inode as the index.  To find the
name of your tty you would just make a request of the database.  You could
then feed all of the tty device names to this program at boot-time to
create the index.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh at rpp386.cactus.org



More information about the Comp.unix.wizards mailing list