X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetpass.c;h=226be155b19ec9807ee02ed1df966e83990c0ddc;hb=2df78ba2ce9441243a0e3aa5fa5f5e869af23c51;hp=cdf90ca57da89bef725fb60102722535b537b716;hpb=6bc82919a69f637e184ff3c64882eafff05bbb5c;p=gnulib.git diff --git a/lib/getpass.c b/lib/getpass.c index cdf90ca57..226be155b 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1992-2001, 2003, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1992-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -15,7 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if HAVE_CONFIG_H +#ifndef _LIBC # include #endif @@ -23,23 +24,22 @@ #include -#if !defined WIN32 +#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) #include -#if HAVE_STDIO_EXT_H -# include -#endif -#if !HAVE___FSETLOCKING -# define __fsetlocking(stream, type) /* empty */ +#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING +# if HAVE_STDIO_EXT_H +# include +# endif +#else +# define __fsetlocking(stream, type) /* empty */ #endif #if HAVE_TERMIOS_H # include #endif -#include "getline.h" - #if USE_UNLOCKED_IO # include "unlocked-io.h" #else @@ -139,26 +139,26 @@ getpass (const char *prompt) == fileno (out). The POSIX restrictions are tricky and change from POSIX version to POSIX version, so play it safe and invoke fseek even if in != out. */ - fseek (out, 0, SEEK_CUR); + fseeko (out, 0, SEEK_CUR); if (buf != NULL) { if (nread < 0) - buf[0] = '\0'; + buf[0] = '\0'; else if (buf[nread - 1] == '\n') - { - /* Remove the newline. */ - buf[nread - 1] = '\0'; - if (tty_changed) - { - /* Write the newline that was not echoed. */ - putc_unlocked ('\n', out); - } - } + { + /* Remove the newline. */ + buf[nread - 1] = '\0'; + if (tty_changed) + { + /* Write the newline that was not echoed. */ + putc_unlocked ('\n', out); + } + } } /* Restore the original setting. */ -#if TCSETATTR +#if HAVE_TCSETATTR if (tty_changed) tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s); #endif @@ -170,13 +170,17 @@ getpass (const char *prompt) return buf; } -#else /* WIN32 */ +#else /* W32 native */ /* Windows implementation by Martin Lambers , improved by Simon Josefsson. */ /* For PASS_MAX. */ #include +/* For _getch(). */ +#include +/* For strdup(). */ +#include #ifndef PASS_MAX # define PASS_MAX 512 @@ -199,20 +203,20 @@ getpass (const char *prompt) { c = _getch (); if (c == '\r') - { - getpassbuf[i] = '\0'; - break; - } + { + getpassbuf[i] = '\0'; + break; + } else if (i < PASS_MAX) - { - getpassbuf[i++] = c; - } + { + getpassbuf[i++] = c; + } if (i >= PASS_MAX) - { - getpassbuf[i] = '\0'; - break; - } + { + getpassbuf[i] = '\0'; + break; + } } if (prompt)