linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: I'm really starting to dislike stdio
Date: Thu, 19 Jun 2003 13:26:17 +0200	[thread overview]
Message-ID: <20030619112617.GV6353@lug-owl.de> (raw)
In-Reply-To: <004001c33635$21f3d3a0$e764a8c0@fesnel.noip.org>

[-- Attachment #1: Type: text/plain, Size: 2083 bytes --]

On Thu, 2003-06-19 03:33:16 -0400, John T. Williams <jtwilliams@vt.edu>
wrote in message <004001c33635$21f3d3a0$e764a8c0@fesnel.noip.org>:
> I really appricated the help with the progress bar.
> 
> I have another problem
> 
> I am trying to read in a password from the stdin, but I don't want it to
> display to the screen as the person types it in.
> I either like to mock su, and take input w/o any output, or output a *  for
> each typed character, and I cannot figure out how to get this to work

> and I tried getc from the curses library.
> The problem with all of these is that they only actually do the read part
> after I've hit the <enter> key.  I want it to process each character as it
> is typed.  Anyone who has any ideas or can tell me a better way to read
> characters w/o displaying it to the screen and I'd be greatful.

Terminals are serial equipment with special characteristics:) First, a
call to read() will only return after the user pressed his Enter key
_until_ you fiddle with serial settings:

struct termios termio;
tcgetattr(STDIN_FILENO, &termio);
termio.c_cc[V_MIN] = 1; /* Return after one byte */
tcsetattr(STDIN_FILENO, &termio);
tcflush(STDIN_FILENO, TCIOFLUSH);

(Of course, you need a second struct termios to memcpy() all the old
values to be able to restore the previous state which you're expected to
do.)

The second part is to not let those characters appear at all. This is
done with:

struct termios termio;
tcgetattr(STDIN_FILENO, &termio);
termio_new.c_lflag &= ~ECHO; /* Clear ECHO flag */
tcsetattr(STDIN_FILENO, &termio);
tcflush(STDIN_FILENO, TCIOFLUSH);

(Again, you need to backup old termios settings.)

Serial programming (which this is, after all) isn't 100% simple:(

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
      ret = do_actions((curr | FREE_SPEECH) & ~(IRAQ_WAR_2 | DRM | TCPA));

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2003-06-19 11:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-18  9:58 stdio John T. Williams
2003-06-18 12:02 ` stdio Jan-Benedict Glaw
2003-06-18 12:17 ` stdio Luciano Moreira - igLnx
2003-06-18 13:04 ` stdio Stephen Satchell
2003-06-18 17:45   ` stdio Glynn Clements
2003-06-18 18:30 ` stdio Chris Nanakos
2003-06-19  7:33   ` I'm really starting to dislike stdio John T. Williams
2003-06-19 11:26     ` Jan-Benedict Glaw [this message]
2003-06-19 17:39       ` Glynn Clements
2003-06-19 12:56     ` Andrés Roldán

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030619112617.GV6353@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).