[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getpass.c



  
  Waay back when, Andreas had this to say about Wolfgang Lux's
  patch to getpass.c:

  <flashback>
  From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  Date: Fri, 28 Apr 95 14:37:46 +0200

  |> diff -u -xChangeLog -xMakefile /usr/src/libsrc/getpass.c. /getpass.c
  |> --- /usr/src/libsrc/getpass.c	Tue Mar 14 21:01:08 1995
  |> +++ ./getpass.c	Thu Apr 13 22:52:16 1995
  [...]
  |> +	  l = strlen(buf);
  |> +	  if (buf[l-1] != '\n') {
  |> +	    while (fgetc(tty) != '\n')
  |> +	      /* wait for a newline */ ;
  |> +	  }

      Another Problem: this should check for EOF!  Otherwise
      you'll get an infinite loop.
  </flashback>

  Background: this loop is part of a routine that takes a string
  from a tty, then strips the trailing end-of-line character.
  I modified it to do the same thing if it encounters an EOF:

The typical Unix behavior is that an EOF character is only recognized
if it is the first character in an input stream. If you type a bunch
of characters in response to a prompt, and type an EOF, that will not
terminate the input. So, you only need to check to see if the first
character you read is an EOF. Otherwise, the input line *must* end
with a newline.
  -- Howard