fgetwln(3bsd)
π fgetwln β get a line of wide characters from a stream π
okay bestie, welcome to fgetwln(3bsd), the wide-character line-grabber from the BSD corner of the world. this is the page for it, and we're gonna go through everything, no skipping, no cap. β¨
π LIBRARY
Utility functions from BSD systems β that's libbsd, and you link it with -lbsd. π«Ά
β¨ SYNOPSIS β¨
#include <stdio.h>
#include <wchar.h>
(See libbsd(7) for include usage.)
wchar_t *
fgetwln(FILE * restrict stream, size_t * restrict len);
yeah so those includes are the vibe, and if you're confused about how the includes work in libbsd land, go peek at libbsd(7) β it explains the whole include situation. π§
πΈ DESCRIPTION πΈ
so like. fgetwln() hands you back a pointer to the next line from the stream that stream points at. that's the whole job. π
BUT. and this is the part that gets people β this line is not a standard wide character string, because it does not end with a terminating null wide character. no null terminator, bestie. it's giving "raw vibes only". π
instead, the length of the line β and yes, that includes the final newline β gets stored in the memory location that len points to. so that's how you know where the line ends, since there's no null doing it for you.
π tiny caveat tho: if the line is the last one in a file that does not end in a newline, then the text you get back will not contain a newline. so like, don't go assuming every single return has one, okay?
π₯ RETURN VALUES π₯
on a successful completion, you get a pointer back. iconic. but that pointer becomes invalid after the next I/O operation on stream β whether that operation was successful or not, doesn't matter β or as soon as the stream is closed. so use it fast, or copy it, your call. π
otherwise? NULL. and here's the tea: fgetwln() does not distinguish between end-of-file and error. it just gives you NULL and shrugs. so if you wanna know which one actually happened, you gotta go ask feof(3) and ferror(3). those are the routines that will tell you. π
if an error occurs, the global variable errno is set to indicate the error.
and the end-of-file condition is remembered β even on a terminal β and all subsequent attempts to read will return NULL until that condition is cleared with clearerr(3). so like, it sticks around until you clear it. periodt.
also, the text that the returned pointer points to may be modified, as long as you don't make any changes beyond the returned size. but heads up β those changes are lost as soon as the pointer becomes invalid. so enjoy them while they last. π
π ERRORS π
[EBADF]β the argumentstreamis not a stream open for reading. bestie, you gotta open it for reading. that's the rule.
and also: fgetwln() may fail and set errno for any of the errors specified for the routines mbrtowc(3), realloc(3), or read(2). so if you're debugging, those are the other places to look. π
π¦ SEE ALSO π¦
Debian π July 16, 2004 β that's where this page comes from and when it was stamped, and honestly, a 2004 baddie that's still out here serving wide-character lines? iconic behavior, no notes. go read your lines bestie, ily, bye! πβ¨π«Ά
π¦ where this page comes from
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms