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