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 least n wide characters at ws. no cap, that's on you, not her.

want a nonlocking counterpart? go see unlocked_stdio(3) โœจ

๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

  • if fgetws() is successful, she returns ws ๐Ÿ’–
  • 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 the LC_CTYPE category 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 that fgetws() 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