1getpass(3) Library Functions Manual getpass(3)
2
3
4
6 getpass - get a password
7
9 Standard C library (libc, -lc)
10
12 #include <unistd.h>
13
14 [[deprecated]] char *getpass(const char *prompt);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 getpass():
19 Since glibc 2.2.2:
20 _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
21 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
22 || /* glibc <= 2.19: */ _BSD_SOURCE
23 Before glibc 2.2.2:
24 none
25
27 This function is obsolete. Do not use it. See NOTES. If you want to
28 read input without terminal echoing enabled, see the description of the
29 ECHO flag in termios(3).
30
31 The getpass() function opens /dev/tty (the controlling terminal of the
32 process), outputs the string prompt, turns off echoing, reads one line
33 (the "password"), restores the terminal state and closes /dev/tty
34 again.
35
37 The function getpass() returns a pointer to a static buffer containing
38 (the first PASS_MAX bytes of) the password without the trailing new‐
39 line, terminated by a null byte ('\0'). This buffer may be overwritten
40 by a following call. On error, the terminal state is restored, errno
41 is set to indicate the error, and NULL is returned.
42
44 ENXIO The process does not have a controlling terminal.
45
47 /dev/tty
48
50 For an explanation of the terms used in this section, see at‐
51 tributes(7).
52
53 ┌─────────────────────────────────────┬───────────────┬────────────────┐
54 │Interface │ Attribute │ Value │
55 ├─────────────────────────────────────┼───────────────┼────────────────┤
56 │getpass() │ Thread safety │ MT-Unsafe term │
57 └─────────────────────────────────────┴───────────────┴────────────────┘
58
60 None.
61
63 Version 7 AT&T UNIX. Present in SUSv2, but marked LEGACY. Removed in
64 POSIX.1-2001.
65
67 You should use instead readpassphrase(3bsd), provided by libbsd.
68
69 In the GNU C library implementation, if /dev/tty cannot be opened, the
70 prompt is written to stderr and the password is read from stdin. There
71 is no limit on the length of the password. Line editing is not
72 disabled.
73
74 According to SUSv2, the value of PASS_MAX must be defined in <limits.h>
75 in case it is smaller than 8, and can in any case be obtained using
76 sysconf(_SC_PASS_MAX). However, POSIX.2 withdraws the constants
77 PASS_MAX and _SC_PASS_MAX, and the function getpass(). The glibc
78 version accepts _SC_PASS_MAX and returns BUFSIZ (e.g., 8192).
79
81 The calling process should zero the password as soon as possible to
82 avoid leaving the cleartext password visible in the process's address
83 space.
84
86 crypt(3)
87
88
89
90Linux man-pages 6.05 2023-07-20 getpass(3)