Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!prls!pyramid!ctnews!mitisft!dold From: dold@mitisft.Convergent.COM (Clarence Dold) Newsgroups: comp.unix.wizards Subject: Re: Getting tty name without using ttyname(3) Message-ID: <1398@mitisft.Convergent.COM> Date: 16 Feb 90 00:26:30 GMT References: <673@compel.UUCP> Organization: Convergent Technologies, San Jose, CA Lines: 20 in article <673@compel.UUCP>, her@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@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