Getting tty name without using ttyname(3)

lutmann at geocub.greco-prog.fr lutmann at geocub.greco-prog.fr
Sat Mar 3 03:18:37 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


    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
`-----------------------------'



More information about the Comp.unix.wizards mailing list