1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

use stderr to present the prompt to, make sure to close the fopen()ed

file handle
This commit is contained in:
Daniel Stenberg 2002-07-29 14:15:14 +00:00
parent c051438fa1
commit 14f0dd2dd0

View File

@ -93,14 +93,10 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
#include "memdebug.h" #include "memdebug.h"
#endif #endif
/* no perror? make an fprintf! */
#ifndef HAVE_PERROR
# define perror(x) fprintf(stderr, "Error in: %s\n", x)
#endif
char *getpass_r(const char *prompt, char *buffer, size_t buflen) char *getpass_r(const char *prompt, char *buffer, size_t buflen)
{ {
FILE *infp; FILE *infp;
char infp_fclose = 0;
FILE *outfp; FILE *outfp;
RETSIGTYPE (*sigint)(); RETSIGTYPE (*sigint)();
#ifndef __EMX__ #ifndef __EMX__
@ -127,41 +123,30 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
sigtstp = signal(SIGTSTP, SIG_IGN); sigtstp = signal(SIGTSTP, SIG_IGN);
#endif #endif
if( (infp=fopen("/dev/tty", "r")) == NULL ) infp=fopen("/dev/tty", "r");
{ if( NULL == infp )
infp = stdin; infp = stdin;
} else
if( (outfp=fopen("/dev/tty", "w")) == NULL ) infp_fclose = 1;
{
outfp = stderr; outfp = stderr;
}
infd = fileno(infp); infd = fileno(infp);
outfd = fileno(outfp); outfd = fileno(outfp);
/* dissable echo */ /* dissable echo */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
if(tcgetattr(outfd, &orig) != 0) tcgetattr(outfd, &orig);
{
; /*perror("tcgetattr");*/
}
noecho = orig; noecho = orig;
noecho.c_lflag &= ~ECHO; noecho.c_lflag &= ~ECHO;
if(tcsetattr(outfd, TCSANOW, &noecho) != 0) tcsetattr(outfd, TCSANOW, &noecho);
{
; /*perror("tcgetattr");*/
}
#else #else
# ifdef HAVE_TERMIO_H # ifdef HAVE_TERMIO_H
if(ioctl(outfd, TCGETA, &orig) != 0) ioctl(outfd, TCGETA, &orig);
{
; /*perror("ioctl");*/
}
noecho = orig; noecho = orig;
noecho.c_lflag &= ~ECHO; noecho.c_lflag &= ~ECHO;
if(ioctl(outfd, TCSETA, &noecho) != 0) ioctl(outfd, TCSETA, &noecho);
{
; /*perror("ioctl");*/
}
# else # else
# endif # endif
#endif #endif
@ -187,16 +172,10 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
* user types more than buflen * user types more than buflen
*/ */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
if(tcsetattr(outfd, TCSAFLUSH, &orig) != 0) tcsetattr(outfd, TCSAFLUSH, &orig);
{
; /*perror("tcgetattr");*/
}
#else #else
# ifdef HAVE_TERMIO_H # ifdef HAVE_TERMIO_H
if(ioctl(outfd, TCSETA, &orig) != 0) ioctl(outfd, TCSETA, &orig);
{
; /*perror("ioctl");*/
}
# else # else
# endif # endif
#endif #endif
@ -206,6 +185,9 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
signal(SIGTSTP, sigtstp); signal(SIGTSTP, sigtstp);
#endif #endif
if(infp_fclose)
fclose(infp);
return buffer; /* we always return success */ return buffer; /* we always return success */
} }
#endif /* VMS */ #endif /* VMS */