getpass() — Read a string of characters without echo

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2

both  

Format

#define _XOPEN_SOURCE
#include <unistd.h>

char *getpass(const char *prompt);

General description

The getpass() function opens the process's controlling terminal, writes to that device the NULL-terminated string prompt, disables echoing, reads a string of characters up to the next newline character or EOF, restores the terminal state and closes the terminal.

getpass() only works in an environment where either a controlling terminal exists, or stdin and stderr refer to tty devices. Specifically, it does not work in a TSO environment.

Note:

This function is kept for historical reasons. It was part of the Legacy Feature in Single UNIX Specification, Version 2, but has been withdrawn and is not supported as part of Single UNIX Specification, Version 3.

If it is necessary to continue using this function in an application written for Single UNIX Specification, Version 3, define the feature test macro _UNIX03_WITHDRAWN before including any standard system headers. The macro exposes all interfaces and symbols removed in Single UNIX Specification, Version 3.

Returned value

If successful, getpass() returns a pointer to a NULL-terminated string of at most PASS_MAX bytes that were read from the terminal device.

If unsuccessful, getpass() returns a NULL pointer and the terminal state is restored.

Related information