ttyname() - question

Alan J Rosenthal flaps at dgp.toronto.edu
Fri Sep 1 06:53:50 AEST 1989


cpcahil at virtech.UUCP (Conor P. Cahill) writes:
>I beg to differ.  If the open succeeded you will have gotten a file 
>descriptor for the "controlling terminal", not /dev/tty...
>I can't imagine that there is a kernel out there that will return a 
>file descriptor associated with /dev/tty and then re-maps it to the
>appropriate device for every read and write...

FOR F***K'S SAKE DOES NO ONE CHECK THINGS OUT BEFORE POSTING?

Script started on Thu Aug 31 16:40:46 1989
champlain.dgp% cat ttyname.c
#include <stdio.h>
#include <fcntl.h>

int main()
{
    int fd;
    char *p;
    extern char *ttyname();

    if ((fd = open("/dev/tty", O_RDWR)) < 0)
	perror("/dev/tty");
    else if ((p = ttyname(fd)) == NULL)
	fprintf(stderr, "ttyname failed\n");
    else
	printf("tty is %s\n", p);

    return(0);
}
champlain.dgp% cc ttyname.c
champlain.dgp% a.out
tty is /dev/tty
champlain.dgp% ^D
script done on Thu Aug 31 16:41:04 1989

That was on a sun running 3.5; I got the same output on an iris running sys V
whose motd says "IRIX System V Release 4D1-3.1D".

--

Posting etiquette:
When I saw Karl's posting about /dev/tty, I was surprised and I thought it was
wrong.  But I didn't just bang on my followup key.  I pressed ^Z and typed
"ttyname </dev/tty".  Much to my surprise I got the output "/dev/tty".  It's
quite simple to check before posting.  Remember that when you post hasty
replies you are wasting many people's time, especially by the volume of
followups to your followup which are generated.

ajr



More information about the Comp.lang.c mailing list