The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


getpass - read a string of characters without echo (LEGACY)


#include <unistd.h>

char *getpass(const char *prompt);


The getpass() function opens the process' 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.

This interface need not be reentrant.


Upon successful completion, getpass() returns a pointer to a null-terminated string of at most {PASS_MAX} bytes that were read from the terminal device. If an error is encountered, the terminal state is restored and a null pointer is returned.


The getpass() function may fail if:
The getpass() function was interrupted by a signal.
The process is a member of a background process attempting to read from its controlling terminal, the process is ignoring or blocking the SIGTTIN signal or the process group is orphaned. This error may also be generated for implementation-dependent reasons.
{OPEN_MAX} file descriptors are currently open in the calling process.
The maximum allowable number of files is currently open in the system.
The process does not have a controlling terminal.




The return value points to static data whose content may be overwritten by each call.

This function was marked LEGACY since it provides no functionality which a user could not easily implement, and its name is misleading.




<limits.h>, <unistd.h>.


Derived from System V Release 2.0.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]