inwstr(3NCURSES)
π inwstr β get a wide-character string from a curses window β¨
okay bestie, so this is inwstr(3NCURSES) from the Library calls section, and it's literally the girlboss way to yoink a whole wide-character string out of a curses window. eight functions, one vibe. let's go π«Ά
πΈ NAME πΈ
inwstr, winwstr, mvinwstr, mvwinwstr, innwstr, winnwstr, mvinnwstr, mvwinnwstr β get a wide-character string from a curses window π
β¨ SYNOPSIS β¨
#include <curses.h>
int inwstr(wchar_t * wstr);
int winwstr(WINDOW * win, wchar_t * wstr);
int mvinwstr(int y, int x, wchar_t * wstr);
int mvwinwstr(WINDOW * win, int y, int x, wchar_t * wstr);
int innwstr(wchar_t * wstr, int n);
int winnwstr(WINDOW * win, wchar_t * wstr, int n);
int mvinnwstr(int y, int x, wchar_t * wstr, int n);
int mvwinnwstr(WINDOW * win, int y, int x, wchar_t * wstr, int n);
π¦ DESCRIPTION π¦
so winwstr pulls a wide-character string out of a curses window win. it starts at the cursor, keeps going until the end of the line, and drops the whole thing into wstr. then it slaps a wide null character on the end to terminate it, and β listen β it omits any attributes and the color pair identifier that curses has attached to each character. we're just here for the letters, not the ~lewk~ π
winnwstr is the same energy, except it copies at most n wide characters out of win. and here's the fun part: a negative n means no limit, so winnwstr just does exactly what winwstr does. iconic behaviour honestly π
and if you want the full rundown on all the variants of these functions, that's ncurses(3NCURSES), bestie. it's giving reference material. π
π₯ RETURN VALUE π₯
on a successful run, these functions return the count of wide characters copied from win to wstr β and no, that count does not include the wide null terminator, she's not invited to the party. or they return ERR if things go wrong π
innwstr, winnwstr, mvinnwstr, and mvwinnwstr return ERR if n is insufficiently large to store a complete wide character string. and remember, babes: a curses complex character can contain multiple wide characters, and some of those may be non-spacing. so like. plan accordingly. π
in ncurses, these functions return ERR if:
- the curses screen has not been initialized π
- (for the functions that take a
WINDOWpointer argument)winis a null pointer wstris a null pointer
also, the functions prefixed with mv first perform cursor movement, and they fail if the position (y, x) is outside the window boundaries. stay in your lane, coordinate-wise π
π NOTES π
all of these functions except winnwstr may be implemented as macros. surprise! π
reading a line that overflows the array pointed to bywstrand its variants causes undefined results. no cap. instead, use then-infixed functions with a positivenargument that's no larger than the size of the buffer backingwstr. protect yourself, bestie π«Ά
π EXTENSIONS π
innwstr, winnwstr, mvinnwstr, and mvwinnwstr's acceptance of negative n values is an ncurses extension. not standard, just ncurses being extra β¨
β PORTABILITY β
if your application is out here using ncurses extensions, you should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. gatekeeping your code from the compiler, as you should π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. okay werk.
notwithstanding the foregoing (love that phrase, ate), X/Open Curses Issues 4 and 7 both state that innwstr, winnwstr, mvinnwstr, and mvwinnwstr "fail ... [i]f the array is not large enough to contain any complete characters". strictly interpreted, this means a caller of these functions cannot use their return values to detect truncation of a wide-character string copied from more than one character cell in win. π¬ ncurses, however, reports any truncation with ERR. ncurses said "not on my watch."
X/Open Curses specifies inwstr, winwstr, mvinwstr, and mvwinwstr as returning OK rather than a (wide) character count β which is lowkey wild, because that's unlike their non-wide counterparts instr, winstr, mvinstr, and mvwinstr. ncurses regards this inconsistency as an error in the standard. periodt. π
π HISTORY π
the System V Interface Definition, Version 4 (1995), specified winwstr and winnwstr (and the usual variants). these were later additions to SVr4.x β they did not appear in the first SVr4 (1989). the glow-up took a minute π
and get this: their synopses described each function as taking an argument of type pointer-to-char instead of pointer-to-wchar_t, despite describing them as "returning the string of wchar_t in str". presumably this was an error in the System V Interface Definition. girlie was typing too fast and never proofread. π
π SEE ALSO π
instr(3NCURSES)β describes comparable functions of the ncurses library in its non-wide-character configuration. same vibe, smaller letters.ncurses(3NCURSES)in_wch(3NCURSES)in_wchstr(3NCURSES)
and that's the whole page, bestie β no skips, no summaries, every flag and caveat present and accounted for π
ncurses 6.6 β 2025-10-20 πΈ mwah, stay safe out there and don't overflow your buffers, ily π«Άπβ¨
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 2002-2012,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms