delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/02/01/10:35:39

From: assar AT sics DOT se (Assar Westerlund)
Subject: b17.1: Can't read without echo from /dev/tty
1 Feb 1997 10:35:39 -0800 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <5liv4cmnlf.fsf.cygnus.gnu-win32@assaris.sics.se>
Mime-Version: 1.0 (generated by tm-edit 7.68)
Original-To: gnu-win32 AT cygnus DOT com
X-Mailer: Gnus v5.2.40/Emacs 19.34
Original-Sender: owner-gnu-win32 AT cygnus DOT com

When using b17.1 under NT 3.51, I discovered that /dev/tty behaves
differently from stdin.  When trying to read from /dev/tty with echo
turned off, it just hangs.  The same program works fine with stdin.

This test case works:
----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <termios.h>

int main ()
{
  struct termios t;
  char str[256];
  FILE *f = stdin;

  if (tcgetattr (fileno(f), &t))
    perror ("tcgetattr");
  t.c_lflag &= ~ECHO;
  if (tcsetattr (fileno(f), TCSANOW, &t))
    perror ("tcsetattr");
  fgets (str, sizeof(str), f);
  t.c_lflag |= ECHO;
  if (tcsetattr (fileno(f), TCSANOW, &t))
    perror ("tcsetattr");
  return 0;
}
----------------------------------------------------------------------

And this test case just hangs:
----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <termios.h>

int main ()
{
  struct termios t;
  char str[256];
  FILE *f = fopen("/dev/tty", "r");

  if (tcgetattr (fileno(f), &t))
    perror ("tcgetattr");
  t.c_lflag &= ~ECHO;
  if (tcsetattr (fileno(f), TCSANOW, &t))
    perror ("tcsetattr");
  fgets (str, sizeof(str), f);
  t.c_lflag |= ECHO;
  if (tcsetattr (fileno(f), TCSANOW, &t))
    perror ("tcsetattr");
  return 0;
}
----------------------------------------------------------------------
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019