Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!natinst!sequoia!rpp386!jfh From: jfh@rpp386.cactus.org (John F. Haugh II) Newsgroups: comp.unix.wizards Subject: Re: Getting tty name without using ttyname(3) Summary: How about higher technology??? Message-ID: <17954@rpp386.cactus.org> Date: 16 Feb 90 06:12:38 GMT References: <673@compel.UUCP> <15137:00:09:24@stealth.acf.nyu.edu> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 20 In article <15137:00:09:24@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >In article <673@compel.UUCP> her@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@rpp386.cactus.org