Given the following...
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
int fd;
char *name;
if ((fd = open("/dev/tty", O_RDONLY)) < 0) {
fprintf(stderr, "open error\n");
exit(1);
}
name = ttyname(fd);
printf("real ttyname is: %s\n", name);
close(fd);
exit(0);
}
When I run it on my local linux box, I see the following...
$ ./me
real ttyname is: /dev/tty
even though real actual tty is..
When I run this same code on a remote machine that uses FreeBSD, I see the following..,
% ./me
real ttyname is: /dev/ttyp5
In this cae it matches what tty produces...
Why wouldn't the Linux box produce the actual ttyname in this case? Why does it just show /dev/tty and not the actual terminal name?