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, an int) from stream. It's provided for compatibility with SVr4. But bestie, we recommend you use fread(3) instead. for real. please.
  • putw() writes the word w (that is, an int) to stream. Also provided for compatibility with SVr4, and also β€” we recommend you use fwrite(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 the getw(3) entry. that's the source, the version, and the date, all wrapped up with a little bow πŸŽ€ slay, thanks for reading, go use fread(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms