Getting tty name without using ttyname(3)

Clarence Dold dold at mitisft.Convergent.COM
Fri Feb 16 11:26:30 AEST 1990


in article <673 at compel.UUCP>, her at compel.UUCP (Helge Egelund Rasmussen) says:

> I need to write a replacement for the SYSV release 3 ttyname(3) function.
> As far as I can see by prof'ing a test program, ttyname calls stat(2)
> on the files in /dev until it finds the correct tty (its doing about 300
> stat calls!).

As a first shot, try fstat(0, buf), looking at buf.st_rdev to get your 
minor device number.  Then do a stat of /dev/ttyXXX where XXX is the minor
device number of your tty, and see if buf.st_ino matches.

This only works if the minor device lines up with the port number, but 
it probably does.

If this fails, then call ttyname().
-- 
---
Clarence A Dold - dold at tsmiti.Convergent.COM            (408) 435-5293
               ...pyramid!ctnews!tsmiti!dold        FAX (408) 435-3105
               P.O.Box 6685, San Jose, CA 95150-6685         MS#10-007



More information about the Comp.unix.wizards mailing list