* Copyright (c) 1988 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)getpass.c 5.7 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
static char buf
[_PASSWORD_LEN
+ 1];
* read and write to /dev/tty if possible; else read from
* stdin and write to stderr.
if ((outfp
= fp
= fopen("/dev/tty", "w+")) == NULL
) {
* note - blocking signals isn't necessarily the
* right thing, but we leave it for now.
omask
= sigblock(sigmask(SIGINT
)|sigmask(SIGTSTP
));
(void)tcgetattr(fileno(fp
), &term
);
if (echo
= (term
.c_lflag
& ECHO
)) {
(void)tcsetattr(fileno(fp
), TCSAFLUSH
, &term
);
(void)fputs(prompt
, outfp
);
rewind(outfp
); /* implied flush */
for (p
= buf
; (ch
= getc(fp
)) != EOF
&& ch
!= '\n';)
if (p
< buf
+ _PASSWORD_LEN
)
(void)write(fileno(outfp
), "\n", 1);
tcsetattr(fileno(fp
), TCSAFLUSH
, &term
);