svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
getstr(3x)
curs_getstr(3x) Library calls curs_getstr(3x)
NAME
getstr, getnstr, wgetstr, wgetnstr, mvgetstr, mvgetnstr, mvwgetstr,
mvwgetnstr - read a character string from curses terminal keyboard
SYNOPSIS
#include <ncursesw/curses.h>
int getstr(char * str);
int wgetstr(WINDOW * win, char * str);
int mvgetstr(int y, int x, char * str);
int mvwgetstr(WINDOW * win, int y, int x, char * str);
int getnstr(char * str, int n);
int wgetnstr(WINDOW * win, char * str, int n);
int mvgetnstr(int y, int x, char * str, int n);
int mvwgetnstr(WINDOW * win, int y, int x, char * str,
int n);
DESCRIPTION
wgetstr populates a user-supplied string buffer str by repeatedly call‐
ing wgetch(3X) with the win argument until a line feed or carriage re‐
turn character is input. The function
• does not copy the terminating character to str;
• always terminates str with a null character;
• interprets the screen's erase and kill characters (see
erasechar(3X) and killchar(3X));
• recognizes function keys only if the screen's keypad option is en‐
abled (see keypad(3X));
• treats the function keys KEY_LEFT and KEY_BACKSPACE the same as the
erase character; and
• discards function key inputs other than those treated as the erase
or kill characters, calling beep(3X).
The erase character replaces the character at the end of the buffer
with a null character, while the kill character does the same for the
entire buffer.
If the screen's echo option is enabled (see echo(3X)), wgetstr updates
win with waddch(3X). Further,
• the erase character and its function key synonyms move the cursor
to the left, and
• the kill character returns the cursor to where it was located when
wgetstr was called.
wgetnstr is similar, but reads at most n characters, aiding the appli‐
cation to avoid overrunning the buffer to which str points. curses ig‐
nores an attempt to input more than n characters (other than the termi‐
nating line feed or carriage return), calling beep(3X). If n is nega‐
tive, wgetn_wstr reads up to LINE_MAX characters (see sysconf(3)).
ncurses(3X) describes the variants of these functions.
RETURN VALUE
These functions return OK on success and ERR on failure.
In ncurses, these functions fail if
• the curses screen has not been initialized,
• (for functions taking a WINDOW pointer argument) win is a null
pointer,
• str is a null pointer, or
• an internal wgetch(3X) call fails.
Further, in ncurses, these functions return KEY_RESIZE if a SIGWINCH
event interrupts the function.
Functions prefixed with “mv” first perform cursor movement and fail if
the position (y, x) is outside the window boundaries.
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
box; cbp-1 | cbp-1 l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE = Availabil‐
ity library/ncurses = Stability Uncommitted
NOTES
All of these functions except wgetnstr may be implemented as macros.
Reading input that overruns the buffer pointed to by str causes unde‐
fined results. Use the n-infixed functions, and allocate sufficient
storage for str — at least n+1 times sizeof(char).
While these functions conceptually implement a series of calls to
wgetch, they also temporarily change properties of the curses screen to
permit simple editing of the input buffer. Each function saves the
screen's state, calls nl(3X), and, if the screen was in canonical
(“cooked”) mode, cbreak(3X). Before returning, it restores the saved
screen state. Other implementations differ in detail, affecting which
control characters they can accept in the buffer; see section “PORTA‐
BILITY” below.
Source code for open source software components in Oracle Solaris can
be found at https://www.oracle.com/downloads/opensource/solaris-source-
code-downloads.html.
This software was built from source available at:
https://github.com/oracle/solaris-userland
The original community source was downloaded from:
https://invisible-mirror.net/archives/ncurses/cur‐
rent/ncurses-6.5-20250614.tgz
Further information about this software can be found on the open source
community website at https://invisible-island.net/ncurses/.
EXTENSIONS
getnstr, wgetnstr, mvgetnstr, and mvwgetnstr's handing of negative n
values is an ncurses extension.
The return value KEY_RESIZE is an ncurses extension.
PORTABILITY
Applications employing ncurses extensions should condition their use on
the visibility of the NCURSES_VERSION preprocessor macro.
X/Open Curses Issue 4 describes these functions. It specifies no error
conditions for them, but indicates that wgetnstr and its variants read
“the entire multi-byte sequence associated with a character” and “fail”
if n and str together do not describe a buffer “large enough to contain
any complete characters”. In ncurses, however, wgetch reads only sin‐
gle-byte characters, so this scenario does not arise.
SVr4 describes a successful return value only as “an integer value
other than ERR”.
SVr3 and early SVr4 curses implementations did not reject function
keys; the SVr4 documentation asserted that, like the screen's erase and
kill characters, they were
interpreted, as well as any special keys (such as function keys,
“home” key, “clear” key, etc.)
without further detail. It lied. The “character” value appended to
the string by those implementations was predictable but not useful —
being, in fact, the low-order eight bits of the key code's KEY_ con‐
stant value. (The same language, unchanged except for styling, sur‐
vived into X/Open Curses Issue 4, Version 2 but disappeared from Is‐
sue 7.)
A draft of X/Open Curses Issue 5 (which never saw final release) stated
that these functions “read at most n bytes” but did not state whether
the terminating null character counted toward that limit. X/Open
Curses Issue 7 changed that to say they “read at most n-1 bytes” to al‐
low for the terminating null character. As of 2018, some implementa‐
tions count it, some do not.
• ncurses 6.1 and PDCurses do not count the null character toward the
limit, while Solaris and NetBSD curses do.
• Solaris xcurses offers both behaviors: its wide-character
wgetn_wstr reserves room for a wide null character, but its non-
wide wgetnstr does not consistently count a null character toward
the limit.
X/Open Curses does not specify what happens if the length n is nega‐
tive.
• ncurses 6.2 uses LINE_MAX or a larger (system-dependent) value pro‐
vided by sysconf(3). If neither LINE_MAX nor sysconf is available,
ncurses uses the POSIX minimum value for LINE_MAX (2048). In ei‐
ther case, it reserves a byte for the terminating null character.
• In SVr4 curses, a negative n tells wgetnstr to assume that the
caller's buffer is large enough to hold the result; that is, the
function then acts like wgetstr. X/Open Curses does not mention
this behavior (or anything related to nonpositive n values), how‐
ever most curses libraries implement it. Most implementations nev‐
ertheless enforce an upper limit on the count of bytes they write
to the destination buffer str.
• BSD curses lacked wgetnstr, and its wgetstr wrote to str unbound‐
edly, as did that in SVr2.
• PDCurses, and SVr3 and later, and Solaris curses limit both func‐
tions to writing 256 bytes. Other System V-based platforms likely
use the same limit.
• Solaris xcurses limits the write to LINE_MAX bytes (see
sysconf(3)).
• NetBSD 7 curses imposes no particular limit on the length of the
write, but does validate n to ensure that it is greater than zero.
A comment in NetBSD's source code asserts that SUSv2 specifies
this.
Implementations vary in their handling of input control characters.
• While they may enable the screen's echo option, some do not take it
out of raw mode, and may take cbreak mode into account when decid‐
ing whether to handle echoing within wgetnstr or to rely on it as a
side effect of calling wgetch.
• Originally, ncurses, like its progenitor pcurses, had its wgetnstr
call noraw and cbreak before accepting input. That may have been
done to make function keys work; it is not necessary with modern
ncurses.
Since 1995, ncurses has provided handlers for SIGINTR and SIGQUIT
events, which are typically generated at the keyboard with ^C and
^\ respectively. In cbreak mode, those handlers catch a signal and
stop the program, whereas other implementations write those charac‐
ters into the buffer.
• Starting with ncurses 6.3 (2021), wgetnstr preserves raw mode if
the screen was already in that state, allowing one to enter the
characters the terminal interprets as interrupt and quit events
into the buffer, for better compatibility with SVr4 curses.
HISTORY
4BSD (1980) introduced wgetstr along with its variants.
SVr3.1 (1987) added wgetnstr, but none of its variants.
X/Open Curses Issue 4 (1995) specified getnstr, mvgetnstr, and
mvwgetnstr.
SEE ALSO
curs_get_wstr(3X) describes comparable functions of the ncurses library
in its wide-character configuration (ncursesw).
curses(3X), curs_addch(3X), curs_getch(3X), curs_inopts(3X),
curs_termattrs(3X),
ncurses 6.5 2025-04-05 curs_getstr(3x)