fgetws(3)
โจ fgetws โจ
okay bestie, so this is a page from the Library Functions Manual (yes, the man pages, we love her) and today's main character is fgetws โ she reads a wide-character string from a FILE stream ๐
๐ธ NAME ๐ธ
fgetws โ read a wide-character string from a FILE stream
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <wchar.h>
wchar_t *fgetws(int n;
wchar_t ws[restrict n], int n, FILE *restrict stream);
๐ DESCRIPTION ๐
okay so fgetws() is literally the wide-character equivalent of fgets(3). she reads a string of at most n-1 wide characters into the wide-character array that ws points at, and then she pops a terminating null wide character (L'\0') on the end. iconic behavior, truly.
she stops reading wide characters as soon as she's encountered and stored a newline wide character. she also stops when the end of stream is reached. so like, she knows when to leave the party ๐ซถ
โ ๏ธ bestie listen โ the programmer must make sure there's room for at leastnwide characters atws. no cap, that's on you, not her.
want a nonlocking counterpart? go see unlocked_stdio(3) โจ
๐ฅ RETURN VALUE ๐ฅ
- if
fgetws()is successful, she returnsws๐ - if the end of stream was already reached, or if an error occurred, she returns
NULL๐ญ
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
- Interface:
fgetws()- Attribute: Thread safety
- Value: MT-Safe
(so like, she's MT-Safe โ thread safe, periodt ๐ค)
๐ STANDARDS ๐
C11, POSIX.1-2008.
๐ฆ HISTORY ๐ฆ
POSIX.1-2001, C99.
๐ NOTES ๐
- the behavior of
fgetws()depends on theLC_CTYPEcategory of the current locale. locale check first, always ๐ - in the absence of additional information passed to the
fopen(3)call, it's reasonable to expect thatfgetws()will actually read a multibyte string from the stream and then convert it to a wide-character string. slay, conversion arc โจ - this function is unreliable, because it does not permit you to deal properly with null wide characters that may be present in the input. not me calling out a function like this ๐ for real though, that's a genuine limitation โ don't build your whole parser on her if your input might have null wide chars in it ๐
๐ SEE ALSO ๐
okay that's the whole page, bestie ๐
this was Linux man-pages version 6.20, dated 2026-02-08 โ go forth and read your wide strings responsibly, mwah ๐๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms