fgetwc(3)
๐ fgetwc โ bestie edition ๐
okay so this is fgetwc(3), a Library Functions Manual page, and it's literally just about reading a wide character from a FILE stream. two functions: fgetwc and getwc. that's the whole vibe. let's go ๐ฆ
โจ NAME โจ
fgetwc, getwc โ read a wide character from a FILE stream ๐
๐ LIBRARY ๐
Standard C library, i.e. libc, and you link it with -lc. periodt.
๐ธ SYNOPSIS ๐ธ
#include <stdio.h>
#include <wchar.h>
wint_t fgetwc(FILE *stream);
wint_t getwc(FILE *stream);
๐ซถ DESCRIPTION ๐ซถ
so fgetwc() is the wide-character equivalent of the fgetc(3) function, no cap. it reads a wide character from stream and hands it right back to you. that's it, that's the function.
but listen โ if the end of stream is reached, or if ferror(stream) becomes true, it returns WEOF instead. and if a wide-character conversion error happens, it sets errno to EILSEQ and returns WEOF. so many WEOFs. it's giving "we tried our best but no" ๐ญ
then there's getwc(). it's either a function or a macro, and it functions identically to fgetwc(). key word: identically. but here's the tea โ because it may be implemented as a macro, it may evaluate its argument more than once. โ ๏ธ so if you're passing something with side effects, bestie, that's on you.
and the manpage itself says, and I quote the energy exactly: there is no reason ever to use it. ๐ iconic. brutal. correct.
if you want the nonlocking counterparts, go see unlocked_stdio(3) โ we love a spinoff series. ๐
๐ฅ RETURN VALUE ๐ฅ
on success, fgetwc() returns the next wide-character from the stream. slay.
otherwise it returns WEOF, and errno is set to indicate the error. so always check your errno, besties, that's the vibe check you actually need.
๐ ERRORS ๐
apart from the usual ones, there is exactly one listed here:
EILSEQโ the data obtained from the input stream does not form a valid character. it's not a character, it never was a character, the conversion said no. ๐
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
fgetwc(),getwc()โ Thread safety:MT-Safe- Interface:
fgetwc(),getwc() - Attribute: Thread safety
- Value:
MT-Safe
(that's the little table from the page, unfolded so it doesn't get squished. MT-Safe means you're safe in threads, go off ๐)
โญ STANDARDS โญ
C11, POSIX.1-2008. certified, official, on the standards list. ๐
๐ง HISTORY ๐ง
POSIX.1-2001, C99. it's been around, it's got lore, it's a legacy icon.
๐ NOTES ๐
the behavior of fgetwc() depends on the LC_CTYPE category of the current locale. so your locale is lowkey the main character here, don't forget it.
and in the absence of additional information passed to the fopen(3) call, it is reasonable to expect that fgetwc() will actually read a multibyte sequence from the stream and then convert it to a wide character. so: multibyte in, wide char out. the little transformation arc we deserve. โจ
ngl if the locale is wrong, everything is wrong. set your locale, bestie, it's not optional. ๐จ
๐ SEE ALSO ๐
the whole wide-character friend group, fr fr. go read them too, they're all canon. ๐ซถ
and that's the page!! ๐ this was Linux man-pages 6.20, dated 2026-02-08, and yeah we're all living in version fgetwc(3)'s world now. mwah, take care of your streams, drink water, check errno ๐
๐๐
๐ฆ 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