Imported Upstream version 7.59.0
[platform/upstream/curl.git] / src / tool_getpass.c
index 4c8dcb9..e5e2d6d 100644 (file)
@@ -5,11 +5,11 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
  *
  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  * copies of the Software, and permit persons to whom the Software is
@@ -52,9 +52,9 @@
 #  endif
 #endif
 
-#define _MPRINTF_REPLACE
-#include <curl/mprintf.h>
-
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #include "tool_getpass.h"
 
 #include "memdebug.h" /* keep this as LAST include */
@@ -207,18 +207,16 @@ static bool ttyecho(bool enable, int fd)
 #endif
     return TRUE; /* disabled */
   }
-  else {
-    /* re-enable echo, assumes we disabled it before (and set the structs we
-       now use to reset the terminal status) */
+  /* re-enable echo, assumes we disabled it before (and set the structs we
+     now use to reset the terminal status) */
 #ifdef HAVE_TERMIOS_H
-    tcsetattr(fd, TCSAFLUSH, &withecho);
+  tcsetattr(fd, TCSAFLUSH, &withecho);
 #elif defined(HAVE_TERMIO_H)
-    ioctl(fd, TCSETA, &withecho);
+  ioctl(fd, TCSETA, &withecho);
 #else
-    return FALSE; /* not enabled */
+  return FALSE; /* not enabled */
 #endif
-    return TRUE; /* enabled */
-  }
+  return TRUE; /* enabled */
 }
 
 char *getpass_r(const char *prompt, /* prompt to display */
@@ -229,7 +227,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
   bool disabled;
   int fd = open("/dev/tty", O_RDONLY);
   if(-1 == fd)
-    fd = 1; /* use stdin if the tty couldn't be used */
+    fd = STDIN_FILENO; /* use stdin if the tty couldn't be used */
 
   disabled = ttyecho(FALSE, fd); /* disable terminal echo */
 
@@ -246,7 +244,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
     (void)ttyecho(TRUE, fd); /* enable echo */
   }
 
-  if(1 != fd)
+  if(STDIN_FILENO != fd)
     close(fd);
 
   return password; /* return pointer to buffer */