delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/07/08:17:52

From: "Dan, Ho-Jin" <naturalis AT cais DOT kaist DOT ac DOT kr>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Getch() in UNIX
Date: Thu, 07 May 1998 09:29:54 +0000
Organization: KAIST
Lines: 42
Message-ID: <35517F12.2ECAC739@cais.kaist.ac.kr>
References: <354EE6B2 DOT 41C6 AT cc DOT hut DOT fi>
NNTP-Posting-Host: casad4.kaist.ac.kr
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

#include <termio.h>
#include <sys/ioctl.h>

int getch() {
   struct termio o, n;
   char c;

   ioctl(0, TCGETA, &o);
   ioctl(0, TCGETA, &n);

   n.c_lflag &= ~(ICANON | ECHO);
   n.c_cc[VMIN] = 1;
   n.c_cc[VTIME]= 0;

   ioctl(0, TCSETA, &n);
    while(read(0, &c, 1) <= 0);
   ioctl(0, TCSETA, &o);

   return (int)c;
}



Ville Lundberg wrote:

> I'm putting up a server and writing a program to it that asks for an
> password. I first wrote the program at home with DJGPP to DOS, and
> thought it would compile in UNIX. But it didn't, and I found out that it
> was because UNIX hasn't GETCH() as DOS does.
> So could anyone show me how to write that little piece of code that ask
> for the password WITHOUT echoing it to screen? I mean, a password that
> anyone can see by lookin over the shoulder is quite useless, isn't it?
> ;-)   Thanks,
>          --Ville
>
> =-----=
> 51) Pelimiehet ei tee virheitä.
> Ville Lundberg   vlundber AT cc DOT hut DOT fi   www.hut.fi/~vlundber/pelimiehet
> -----=



- Raw text -


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