Path: utzoo!attcan!uunet!mcsun!inria!geocub!lutmann From: lutmann@geocub.greco-prog.fr Newsgroups: comp.unix.wizards Subject: Re: Getting tty name without using ttyname(3) Message-ID: <1677@geocub.greco-prog.fr> Date: 2 Mar 90 16:18:37 GMT References: <673@compel.UUCP> <15137:00:09:24@stealth.acf.nyu.edu> Sender: news@geocub.greco-prog.fr Reply-To: lutmann@goofi.UUCP (Johan: Pourquoi tant de Haine?) Organization: ENSERB, Computer Science University, Bordeaux, FRANCE Lines: 30 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 Ttyname() scans the whole /dev ! But I'm not sure that the prefix tty is enough... Don't forget /dev/console, pty... and so on (;-) What you can do, all of your ttys installed, is to build a sort of hash-table containing the inode of all these ttys. It'll reduce the numbers of tests, and after two or three accesses in this table, you'll get it ! Disadvantage : this table is about 4 Kb... *Advantages* : easy and it seems there's nothing faster ! Johan. .-----------------------------. | Johan | ...!uunet!mcvsun!inria!geocub!goofi!lutmann | On goofi, at ENSERB, France | ...!uunet!mcvsun!inria!geocub!deimos!pat `-----------------------------'