Hi
On Sun, Sep 03, 2006 at 11:45:14AM +0100, Reuben Thomas wrote:
> On Sun, 3 Sep 2006, Ola Lundqvist wrote:
>
> >I tried to implement a getpass function myself but I got into a number
> >of problems, like: surpressing character echoing, getc seem not to return
> >until newline is pressed and so on... I have tried fread and many other
> >ways but without success.
>
> I have had a look at getpass in glibc, and it seems to suffer somewhat
> from relying on the internals of glibc, although a brief inspection
> suggests that it is possible to extract working POSIX code.
>
> However, I'm more attracted by the following code, which I found in the
> glibc info documentation:
>
> #include <termios.h>
> #include <stdio.h>
>
> ssize_t
> my_getpass (char **lineptr, size_t *n, FILE *stream)
> {
> struct termios old, new;
> int nread;
>
> /* Turn echoing off and fail if we can't. */
> if (tcgetattr (fileno (stream), &old) != 0)
> return -1;
> new = old;
> new.c_lflag &= ~ECHO;
> if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0)
> return -1;
>
> /* Read the password. */
> nread = getline (lineptr, n, stream);
>
> /* Restore terminal. */
> (void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
>
> return nread;
> }
>
> How does that look?
Looks good.
> BTW, this brings up one vexed point: the info docs are under the GFDL,
> not the GPL. I'll check that the code examples are (as the GFDL itself
> suggests) under a suitable license; I can't find anything in the docs
> themselves, so I'm posting to glibc-bugs.
That can be a problem however. On the other hand it is such
a small thing that ut may not be copyrighted at all. But if you
can find this as a gpl:ed (or similar) licensed, it would be
really nice.
Regards,
// Ola
> --
> http://rrt.sc3d.org/ | fantasize, a. as big as fizzy orange
>
>
--
--------------------- Ola Lundqvist ---------------------------
/ [EMAIL PROTECTED] Annebergsslingan 37 \
| [EMAIL PROTECTED] 654 65 KARLSTAD |
| +46 (0)54-10 14 30 +46 (0)70-332 1551 |
| http://www.opal.dhs.org UIN/icq: 4912500 |
\ gpg/f.p.: 7090 A92B 18FE 7994 0C36 4FE4 18A1 B1CF 0FE5 3DD9 /
---------------------------------------------------------------
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]