getw(3)
β¨ getw β bestie edition β¨
okay so this is getw(3) from the Library Functions Manual, and honestly? it's giving legacy π but we're gonna learn it anyway because knowing old code is a flex, periodt.
π NAME π
getw, putw β input and output of words (ints)
like. the word here means an int. not a word like a string. i know. i KNOW. naming is a mess, we move.
π LIBRARY π
Standard C library (libc, -lc)
π¦ SYNOPSIS π¦
#include <stdio.h>
int getw(FILE *stream);
int putw(int w, FILE *stream);
πΈ Feature Test Macro Requirements for glibc πΈ
(peep feature_test_macros(7) if you're new here, bestie)
getw(), putw():
- Since glibc 2.3.3:
_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
- Before glibc 2.3.3:
_SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE
those macros are the bouncers at the club and you gotta know the right password, no cap π₯
π DESCRIPTION π
getw()reads a word (that is, anint) fromstream. It's provided for compatibility with SVr4. But bestie, we recommend you usefread(3)instead. for real. please.putw()writes the wordw(that is, anint) tostream. Also provided for compatibility with SVr4, and also β we recommend you usefwrite(3)instead. same energy. π«Ά
not me telling you twice to use the newer functions. that's not a suggestion, that's a β¨lifestyleβ¨
π RETURN VALUE π
Normally, getw() returns the word it read, and putw() returns 0. On error, they return EOF.
and that's the whole problem, which we will get to in BUGS. stay tuned. π
π ATTRIBUTES π
for an explanation of the terms used in this section, go look at attributes(7).
getw(),putw()β Thread safety: MT-Safe
MT-Safe means no drama when multiple threads show up. we love a stable queen π
β STANDARDS β
None.
just. none. i said what i said. π
π§ HISTORY π§
SVr4, SUSv2.
ancient. vintage. archival. iconic in a museum-piece way ποΈ
π BUGS π
The value returned on error is also a legitimate data value. So when you get EOF back, you literally cannot tell if it errored or if the file just genuinely contained that value. plot twist that ruins your day.
Good news: ferror(3) can be used to distinguish between the two cases. use it. π
π₯ SEE ALSO π₯
vibe check: this page is from Linux man-pages 6.20, dated 2026-02-08, and it's thegetw(3)entry. that's the source, the version, and the date, all wrapped up with a little bow π slay, thanks for reading, go usefread(3)bestie πβ¨
π¦ 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: Linux-man-pages-copyleft
- Copyright 1995, James R. Van Zandt <jrv@vanzandt.mv.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms