2015-01-02 17:28:19 +01:00
|
|
|
/* Copyright (C) 1992-2015 Free Software Foundation, Inc.
|
1996-12-20 02:39:50 +01:00
|
|
|
This file is part of the GNU C Library.
|
1995-02-18 02:27:10 +01:00
|
|
|
|
1996-12-20 02:39:50 +01:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:58:11 +02:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1995-02-18 02:27:10 +01:00
|
|
|
|
1996-12-20 02:39:50 +01:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 06:58:11 +02:00
|
|
|
Lesser General Public License for more details.
|
1995-02-18 02:27:10 +01:00
|
|
|
|
2001-07-06 06:58:11 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-07-17 10:32:35 +02:00
|
|
|
#include <stdio_ext.h>
|
2004-04-02 02:42:24 +02:00
|
|
|
#include <string.h> /* For string function builtin redirect. */
|
1995-02-18 02:27:10 +01:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-08-30 11:10:12 +02:00
|
|
|
#include <wchar.h>
|
|
|
|
#define flockfile(s) _IO_flockfile (s)
|
|
|
|
#define funlockfile(s) _IO_funlockfile (s)
|
2015-09-08 23:11:03 +02:00
|
|
|
#include <libc-lock.h>
|
1998-07-16 13:44:36 +02:00
|
|
|
|
1996-12-20 02:39:50 +01:00
|
|
|
/* It is desirable to use this bit on systems that have it.
|
1995-02-18 02:27:10 +01:00
|
|
|
The only bit of terminal state we want to twiddle is echoing, which is
|
|
|
|
done in software; there is no need to change the state of the terminal
|
|
|
|
hardware. */
|
|
|
|
|
|
|
|
#ifndef TCSASOFT
|
|
|
|
#define TCSASOFT 0
|
|
|
|
#endif
|
|
|
|
|
2003-08-30 11:10:12 +02:00
|
|
|
static void
|
|
|
|
call_fclose (void *arg)
|
|
|
|
{
|
|
|
|
if (arg != NULL)
|
|
|
|
fclose (arg);
|
|
|
|
}
|
|
|
|
|
1995-02-18 02:27:10 +01:00
|
|
|
char *
|
|
|
|
getpass (prompt)
|
|
|
|
const char *prompt;
|
|
|
|
{
|
|
|
|
FILE *in, *out;
|
1997-01-06 23:07:28 +01:00
|
|
|
struct termios s, t;
|
|
|
|
int tty_changed;
|
Update.
1999-04-28 Ulrich Drepper <drepper@cygnus.com>
* argp/argp-ba.c (argp_program_bug_address): Don't initialize with 0.
* argp/argp-parse.c (_argp_hang): Likewise.
* argp/argp-pv.c (argp_program_version): Likewise.
* argp/argp-pvh.c (argp_program_version_hook): Likewise.
* inet/ether_hton.c (ether_hton, startp): Likewise.
* inet/ether_ntoh.c (ether_ntoh, startp): Likewise.
* inet/getnetgrent_r.c (setup, startp): Likewise.
* intl/loadmsgcat.c (_nl_msg_cat_cntr): Likewise.
* intl/localealias.c (string_space, string_space_act, string_space_max,
nmap, maxmap): Likewise.
* libio/iopopen.c (proc_file_chain): Likewise.
* libio/oldiopopen.c (old_proc_file_chain): Likewise.
* locale/lc-collate.c (__collate_table, __collate_extra,
__collate_element_hash, __collate_element_strings,
__collate_element_values): Likewise.
* malloc/mcheck.c (mcheck_used): Likewise.
* malloc/mtrace.c (added_atexit_handler): Likewise.
* malloc/set-freeres.c (already_called): Likewise.
* misc/getpass.c (getpass) [buf, bufsize]: Likewise.
* misc/syslog.c (LogStat, LogTag): Likewise.
* nss/XXX-lookup.c (DATABASE_NAME_SYMBOL): Likewise.
* nss/getXXbyYY_r.c (startp): Likewise.
* posix/getopt.c (optarg, __getopt_initialized): Likewise.
* posix/regex.c (init_syntax_once) [done]: Likewise.
(debug): Likewise.
* string/strfry.c (init): Likewise.
* sunrpc/svc_run.c (svc_top): Likewise.
* posix/euidaccess.c (have_ids): Likewise.
* sysdeps/unix/sysv/linux/poll.c (must_emulate): Likewise.
* sysdeps/unix/sysv/linux/ttyname.c (__ttyname, namelen): Likewise.
* time/getdate.c (getdate_err): Likewise.
* time/tzfile.c (transitions, type_idxs, types, zone_names, leaps):
Likewise.
* time/tzset.c (old_tz, is_initialized): Likewise.
* inet/getnameinfo.c (nrl_domainname): Rewrite to allow initialization
of static data with zero.
* signal/allocrtsig.c (init): Likewise.
* string/Makefile (routines): Add strchrnul.
* string/Versions [GLIBC_2.1.1]: Add strchrnul.
* string/string.c: Add strchrnul prototype.
* include/string.h: Add __strchrnul prototype.
* sysdeps/generic/strchrnul.c: New file.
* sysdeps/i386/strchrnul.S: New file.
* sysdeps/i386/bits/string.c: Add strchrnul optimization.
* sysdeps/i386/i486/bits/string.c: Likewise.
* argp/argp-help.c (argp_args_usage): Use __strchrnul.
* inet/ether_line.c (ether_line): Likewise.
* nscd/nscd_conf.c (nscd_parse_file): Likewise.
* nss/nsswitch.c (nss_parse_file): Likewise.
* posix/execvp.c (execvp): Likewise.
* posix/fnmatch.c (internal_fnmatch): Likewise.
* resolv/res_hconf.c (_res_hconv_init): Likewise.
* resolv/res_init.c (res_init): Likewise.
* stdlib/fmtmsg.c (init): Likewise.
* stdlib/getsubopt.c (getsubopt): Likewise.
* catgets/catgets.c (catopen): Only allocate one memory block.
(catclose): Only one free call necessary.
* catgets/open_catalog.c (__open_catalog): Simplify handling of
file descriptor.
* ctype/ctype-extn.c: Make __toascii_l and __isascii_l alias instead
of real functions. Simplify _tolower and _toupper.
* grp/initgroups.c (compat_call): Remove unnecessary use of pointer
variable.
* iconv/gconv.h (struct gconv_info): Change data element from pointer
to array of size 0.
* iconv/gconv_open.c (__gconv_open): Allocate structures accordingly.
* iconv/gconv_close.c (__gconv_close): Don't free data.
* iconv/gconv_conf.c (add_alias): Avoid searching in tree twice to
insert new alias.
* iconv/gconv_db.c (add_derivation): More efficient copying. Check
for error while inserting in tree.
* include/time.h: Pretty print.
* inet/ruserpass.c: Rewrite use of toktab to avoid string pointers
in table and lots of relocations.
* posix/regex.c (regerror): Rewrite use of re_error_msgid to avoid
string pointers in table and lots of relocations.
* intl/finddomain.c: Remove definition of strchr macro.
* io/ftw.c (nftw_arr, ftw_arr): Make const.
* locale/loadlocale.c (_nl_load_locale): Optimize string copying.
* locale/localeinfo.h (_nl_category_names): Change into an array with
fixed width char string elements.
* locale/setlocale.c (_nl_category_names): Likewise.
(_nl_current): Make global.
* locale/nl_langinfo.c (nldata): Removed. Use _nl_current now.
* malloc/Makefile (distribute): Add stackinfo.h.
* sysdeps/generic/stackinfo.h: New file.
* sysdeps/i386/stackinfo.h: New file.
* posix/execl.c: Use stackinfo.h in optimizing alloca use.
* posix/execle.c: Likewise.
* posix/execlp.c: Likewise.
* nis/nis_table.c (__create_ib_request): Always use realloc.
* posix/execvp.c (execute): Rename to script_execute and keep only
code to execute using shell.
(execvp): Call execv directly and only fall back on script_execute.
* resolv/inet_net_pton.c (inet_net_pton_ipv4): Remove digits define
and always use xdigits instead.
* resolv/res_init.c (res_init): Use rawmemchr instead of strchr
where appropriate.
* stdlib/fpioconst.h (__tens): New declaration.
(struct mp_power): Remove array, add arrayoff element.
* stdlib/fpioconst.c: Replace definitions of _ten_p* arrays by one
__tens array and add in _fpioconst_pow10 offsets into __tens.
* stdio-common/printf_fp.c: Rewrite to use new __tens array.
* stdlib/strtod.c: Likewise.
* stdlib/a64l.c (a64l_table): Avoid unnecessary elements.
* stdlib/exit.c: Rewrite to use __exit_funcs being as sign for end
of the list.
* stdlib/atexit.c (__exit_funcs): Don't initialize.
* stdlib/fmtmsg.c (keywords): Make name element fixed width array.
* sunrpc/clnt_perr.c: Rewrite clnt_sperrno and auth_errmsg to use
a single and an array with offsets.
* sunrpc/des_soft.c (partab): Make it const.
* sunrpc/key_call.c (trytimeout, tottimeout): Make const.
(__key_encryptsession_pk_LOCAL): Don't initialize with 0.
(__key_decryptsession_pk_LOCAL): Likewise.
(__key_gendes_LOCAL): Likewise.
(MESSENGER): Mark const.
(key_call_private_main): Don't initialize with 0.
(use_keyenvoy): Don't initialize with 0.
(key_call): Rewrite to reverse logic of use_doors variable.
* sunrpc/netname.c (OPSYS): Define as array, not pointer.
(startp): Don't initialize with zero.
* sunrpc/openchild.c (_openchild): Make first argument const.
* sunrpc/pmap_rmt.c (timeout): Mark const.
* sunrpc/xcrypt.c (hex): Likewise.
* sysdeps/unix/sysv/linux/getcwd.c: Rewrite to allow omitting
initialization of global variables.
* sysdeps/unix/sysv/linux/getpt.c: Likewise.
* sysdeps/unix/sysv/linux/if_index.c: Likewise.
* termios/tcgetsid.c: Likewise.
* sysdeps/unix/sysv/linux/i386/dl-procinfo.h (x86_cap_flags): Change
fxsr to osfxsr.
* time/tzfile.c (__tzfile_read): Rewrite to allocate only one memory
block. Add function to free memory if wanted.
* time/tzset.c (tzset_internal): Pass extra argument to __tzfile_read.
* wcsmbs/wcsmbsload.c (to_wc, to_mb): Correct initializers.
* wcsmbs/wmemset.c: Little code optimization.
1999-04-29 01:13:52 +02:00
|
|
|
static char *buf;
|
|
|
|
static size_t bufsize;
|
1995-02-18 02:27:10 +01:00
|
|
|
ssize_t nread;
|
|
|
|
|
|
|
|
/* Try to write to and read from the terminal if we can.
|
|
|
|
If we can't open the terminal, use stderr and stdin. */
|
|
|
|
|
2011-11-15 10:24:42 +01:00
|
|
|
in = fopen ("/dev/tty", "w+ce");
|
1995-02-18 02:27:10 +01:00
|
|
|
if (in == NULL)
|
|
|
|
{
|
|
|
|
in = stdin;
|
|
|
|
out = stderr;
|
|
|
|
}
|
|
|
|
else
|
2001-07-17 10:32:35 +02:00
|
|
|
{
|
|
|
|
/* We do the locking ourselves. */
|
2001-07-17 10:34:13 +02:00
|
|
|
__fsetlocking (in, FSETLOCKING_BYCALLER);
|
2001-07-17 10:32:35 +02:00
|
|
|
|
|
|
|
out = in;
|
|
|
|
}
|
1995-02-18 02:27:10 +01:00
|
|
|
|
2003-08-30 11:10:12 +02:00
|
|
|
/* Make sure the stream we opened is closed even if the thread is
|
|
|
|
canceled. */
|
|
|
|
__libc_cleanup_push (call_fclose, in == out ? in : NULL);
|
|
|
|
|
1998-07-16 13:44:36 +02:00
|
|
|
flockfile (out);
|
|
|
|
|
1995-02-18 02:27:10 +01:00
|
|
|
/* Turn echoing off if it is on now. */
|
|
|
|
|
1998-07-16 13:44:36 +02:00
|
|
|
if (__tcgetattr (fileno (in), &t) == 0)
|
1995-02-18 02:27:10 +01:00
|
|
|
{
|
1997-01-06 23:07:28 +01:00
|
|
|
/* Save the old one. */
|
|
|
|
s = t;
|
|
|
|
/* Tricky, tricky. */
|
update from main archive 970226
1997-02-27 05:12 Ulrich Drepper <drepper@cygnus.com>
* manual/Makefile: Add rules to run and distribute xtract-typefun.
* manual/xtract-typefun.awk: New file. Script to extract function,
variable, macro anchor to put into the `dir' file.
* manual/signal.texi: Document difference between SysV and BSD
signal(3) function and add documentation for sysv_signal.
* sysdeps/libm-i387/e_acoshl.c: Clear upper half of word containing
exponent before comparing.
1997-02-27 01:13 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h (htonl, htons, ntohl, ntohs): Change
prototypes to use types with explicit width. `unsigned long' is
different on 64 bit systems.
* sysdeps/unix/sysv/linux/netinet/in.h: Likewise.
* sysdeps/generic/htonl.c: Likewise.
* sysdeps/generic/htons.c: Likewise.
* sysdeps/generic/ntohl.c: Likewise.
* sysdeps/generic/ntohs.c: Likewise.
Suggested by a sun <asun@zoology.washington.edu>.
1997-02-26 08:30 Andreas Jaeger <aj@arthur.pfalz.de>
* math/math.h: Include <__math.h> if __NO_MATH_INLINES is not
defined and we want optimization.
1997-02-27 01:13 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h (htonl, htons, ntohl, ntohs): Change
prototypes to use types with explicit width. `unsigned long' is
different on 64 bit systems.
Suggested by a sun <asun@zoology.washington.edu>.
1997-02-02 19:53 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* misc/getpass.c: Don't disable canonical input.
Reverted patch of Mon Jan 6 01:35:29 1997.
1996-12-14 22:07 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* libio/libioP.h (_IO_finish_t): Take additional parameter, to
match the hidden __in_chrg parameter of the destructor.
(_IO_FINISH): Pass zero for it.
* libio/genops.c (_IO_default_finish): Add second parameter, which
is ignored.
* libio/memstream.c (_IO_mem_finish): Likewise.
* libio/fileops.c (_IO_mem_finish): Likewise.
* libio/strops.c (_IO_str_finish): Likewise. All callers changed.
1997-02-27 00:23 H.J. Lu <hjl@lucon.org>
* time/Makefile: Avoid using patterns in dependencies.
1997-02-26 00:56 Miguel de Icaza <miguel@nuclecu.unam.mx>
* elf/rtld.c: Make _dl_start static. Otherwise the linker on the
SPARC will convert the call _dl_start into a call into the PLT.
* elf/rtld.c (_dl_start): On the SPARC we need to adjust the value
of arg to make it point to the actual values.
* sysdeps/sparc/elf/DEFS.h: New ELF specific version.
* sysdeps/sparc/Dist: Mention sysdeps/sparc/elf/DEFS.h.
* sysdeps/sparc/bsd-_setjmp.S, sysdeps/sparc/bsd-setjmp.S: Make
them PIC aware.
* sysdeps/sparc/dl-machine.h (elf_machine_load_address):
Implemented.
(elf_machine_rela): Make it compile; fix existing relocation
types; add unhandled relocation types.
(ELF_ADJUST_ARG): Get pointer to arguments at program startup.
(RTLD_START): Initial implementation, not yet finished.
* sysdeps/sparc/elf/start.S: Fix.
* sysdeps/sparc/fpu_control.h: Remove duplicate declaration of
__setfpucw.
* sysdeps/sparc/divrem.m4: Make compilable under Linux.
* sysdeps/sparc/rem.S, sysdeps/sparc/sdiv.S, sysdeps/sparc/udiv.S,
sysdeps/sparc/urem.S : Regenerated.
* sysdeps/sparc/setjmp.S: Make it PIC aware.
* sysdeps/unix/sysv/linux/sparc/__sigtrampoline.S: Define
__ASSEMBLY__ before using kernel header.
* sysdeps/unix/sysv/linux/sparc/Makefile: Use -mv8 flag to compile
rtld.c.
* sysdeps/unix/sysv/linux/sparc/brk.c: Implement.
* sysdeps/unix/sysv/linux/sparc/profil-counter.h: Remove code
to handle old signals.
* sysdeps/unix/sysv/linux/sparc/sigaction.c: Implements sigaction
for all Linux/SPARC kernels.
* sysdeps/unix/sysv/linux/sparc/syscall.S: Add code to store
errno using __errno_location.
* sysdeps/unix/sysv/linux/sparc/sysdep.h: Add various handler
macros for assembler sources.
* sysdeps/unix/sysv/linux/sparc/errno.c: Define errno.
1997-02-25 16:02 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* elf/rtld.c (dl_main): Remove dead code that is never executed.
Rename local variable l to main_map where it is used to point to
the load_map for the executable.
1997-02-25 15:03 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* elf/dl-version.c (_dl_check_all_versions): Ignore libraries that
could not be found.
1997-02-24 23:18 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* Makerules: Generate implicit object suffix rules automagically.
(o-iterator): Move before first use.
* Makeconfig (all-object-suffixes): Add .bo suffix.
1997-02-25 15:11 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/libm-i387/e_acoshf.S (__ieee754_acoshf): Test correct
word on stack for overflow.
C++. Use __exception instead.
1997-02-27 07:01:16 +01:00
|
|
|
t.c_lflag &= ~(ECHO|ISIG);
|
1997-01-06 23:07:28 +01:00
|
|
|
tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
|
1995-02-18 02:27:10 +01:00
|
|
|
}
|
|
|
|
else
|
1997-01-06 23:07:28 +01:00
|
|
|
tty_changed = 0;
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
/* Write the prompt. */
|
2005-07-20 19:51:14 +02:00
|
|
|
__fxprintf (out, "%s", prompt);
|
2015-06-17 22:14:18 +02:00
|
|
|
__fflush_unlocked (out);
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
/* Read the password. */
|
|
|
|
nread = __getline (&buf, &bufsize, in);
|
1995-12-17 21:58:55 +01:00
|
|
|
if (buf != NULL)
|
1998-09-09 13:53:19 +02:00
|
|
|
{
|
|
|
|
if (nread < 0)
|
|
|
|
buf[0] = '\0';
|
|
|
|
else if (buf[nread - 1] == '\n')
|
|
|
|
{
|
|
|
|
/* Remove the newline. */
|
|
|
|
buf[nread - 1] = '\0';
|
|
|
|
if (tty_changed)
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 09:43:27 +02:00
|
|
|
/* Write the newline that was not echoed. */
|
2005-07-20 19:51:14 +02:00
|
|
|
__fxprintf (out, "\n");
|
1998-09-09 13:53:19 +02:00
|
|
|
}
|
|
|
|
}
|
1995-02-18 02:27:10 +01:00
|
|
|
|
1997-01-06 23:07:28 +01:00
|
|
|
/* Restore the original setting. */
|
|
|
|
if (tty_changed)
|
|
|
|
(void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
|
1995-02-18 02:27:10 +01:00
|
|
|
|
1998-07-16 13:44:36 +02:00
|
|
|
funlockfile (out);
|
|
|
|
|
2003-08-30 11:10:12 +02:00
|
|
|
__libc_cleanup_pop (0);
|
|
|
|
|
1995-02-18 02:27:10 +01:00
|
|
|
if (in != stdin)
|
|
|
|
/* We opened the terminal; now close it. */
|
|
|
|
fclose (in);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|