5

I know they have different file descriptors, stdxx can be redirected.

int tty_fd = open("/dev/tty", O_RDWR);

So, what's the difference in the codes below(stdxx not redirected):

n = read(tty_fd, buf, sizeof(buf));
n = read(STDIN_FILENO, buf, sizeof(buf));

n = write(tty_fd, buf, sizeof(buf));
n = write(STDOUT_FILENO, buf, sizeof(buf));

is stdxx same as a link to /dev/tty ?

Lubin
  • 55
  • 5
  • If there is no redirection, there is no difference. But how does your program know there is no redirection? – DYZ Jun 08 '17 at 03:24

1 Answers1

1

Unless there is no redirection "/dev/tty" would be used to display both the standard-output or standard-error. You can selectively output your stdout/stderr onto different file descriptors other than /dev/tty.

asatsi
  • 452
  • 2
  • 5