aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-07-29 14:15:14 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-07-29 14:15:14 +0000
commit14f0dd2dd032f520e5368daee14a40434a0e07ac (patch)
treeaafcf75c817ee0c2ce7db5b1e670217fdb4bdf0a
parentc051438fa182b3c7a622cb5ce0262aa41993756b (diff)
use stderr to present the prompt to, make sure to close the fopen()ed
file handle
-rw-r--r--lib/getpass.c54
1 files changed, 18 insertions, 36 deletions
diff --git a/lib/getpass.c b/lib/getpass.c
index 345c2d44d..481578911 100644
--- a/lib/getpass.c
+++ b/lib/getpass.c
@@ -93,14 +93,10 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
#include "memdebug.h"
#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)
{
FILE *infp;
+ char infp_fclose = 0;
FILE *outfp;
RETSIGTYPE (*sigint)();
#ifndef __EMX__
@@ -127,41 +123,30 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
sigtstp = signal(SIGTSTP, SIG_IGN);
#endif
- if( (infp=fopen("/dev/tty", "r")) == NULL )
- {
+ infp=fopen("/dev/tty", "r");
+ if( NULL == infp )
infp = stdin;
- }
- if( (outfp=fopen("/dev/tty", "w")) == NULL )
- {
- outfp = stderr;
- }
+ else
+ infp_fclose = 1;
+
+ outfp = stderr;
+
infd = fileno(infp);
outfd = fileno(outfp);
/* dissable echo */
#ifdef HAVE_TERMIOS_H
- if(tcgetattr(outfd, &orig) != 0)
- {
- ; /*perror("tcgetattr");*/
- }
+ tcgetattr(outfd, &orig);
+
noecho = orig;
noecho.c_lflag &= ~ECHO;
- if(tcsetattr(outfd, TCSANOW, &noecho) != 0)
- {
- ; /*perror("tcgetattr");*/
- }
+ tcsetattr(outfd, TCSANOW, &noecho);
#else
# ifdef HAVE_TERMIO_H
- if(ioctl(outfd, TCGETA, &orig) != 0)
- {
- ; /*perror("ioctl");*/
- }
+ ioctl(outfd, TCGETA, &orig);
noecho = orig;
noecho.c_lflag &= ~ECHO;
- if(ioctl(outfd, TCSETA, &noecho) != 0)
- {
- ; /*perror("ioctl");*/
- }
+ ioctl(outfd, TCSETA, &noecho);
# else
# endif
#endif
@@ -187,16 +172,10 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
* user types more than buflen
*/
#ifdef HAVE_TERMIOS_H
- if(tcsetattr(outfd, TCSAFLUSH, &orig) != 0)
- {
- ; /*perror("tcgetattr");*/
- }
+ tcsetattr(outfd, TCSAFLUSH, &orig);
#else
# ifdef HAVE_TERMIO_H
- if(ioctl(outfd, TCSETA, &orig) != 0)
- {
- ; /*perror("ioctl");*/
- }
+ ioctl(outfd, TCSETA, &orig);
# else
# endif
#endif
@@ -206,6 +185,9 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
signal(SIGTSTP, sigtstp);
#endif
+ if(infp_fclose)
+ fclose(infp);
+
return buffer; /* we always return success */
}
#endif /* VMS */