fgetln(3bsd)
π fgetln β get a line from a stream π
okay bestie, so this one lives in the libbsd zone β the manual name is fgetln(3bsd) and it's serving LOCAL energy, iykyk.
β¨ LIBRARY β¨
Utility functions from BSD systems β that's libbsd, and you link it with -lbsd. π«Ά
πΈ SYNOPSIS πΈ
#include <stdio.h>
(See libbsd(7) for include usage.)
char *
fgetln(FILE *stream, size_t *len);
heads up, the whole#includesituation has β¨loreβ¨ β go readlibbsd(7)for the include usage deets. π
π¦ DESCRIPTION π¦
so fgetln() hands you back a pointer to the next line from the stream that stream points at. main character behavior fr.
but okay, plot twist: this line is NOT a C string. it does not end with a terminating NUL character. nope. not a vibe it's doing. π
the length of the line β including the final newline β gets stored in the memory location that len points to, and upon successful completion it is guaranteed to be greater than 0. periodt.
(not me reminding you tho: if the line is the last one in a file that does not end in a newline, the returned text will not contain a newline. just so you know. π )
π RETURN VALUES π
upon successful completion, a pointer is returned. slay.
but bestie, listen β that pointer becomes invalid after the next I/O operation on stream (whether it succeeded or not, doesn't matter) or as soon as the stream is closed. so don't get attached. π
otherwise, NULL is returned.
fgetln() does not distinguish between end-of-file and error. so you gotta call feof(3) and ferror(3) to figure out which one actually happened. the way it just won't tell youβ¦ π
if an error occurs, the global variable errno is set to indicate the error.
the end-of-file condition is remembered β even on a terminal β and all subsequent attempts to read will return NULL until the condition is cleared with clearerr(3). so it's holding a grudge until you clear it. π
the text that the returned pointer points to may be modified, provided that no changes are made beyond the returned size. and those changes are lost as soon as the pointer becomes invalid. gone. poof. β¨
π₯ ERRORS π₯
[EBADF]β the argumentstreamis not a stream open for reading. like, you tried to read from something that isn't reading. not the vibe. π«
also, fgetln() may fail and set errno for any of the errors specified for the routines fflush(3), malloc(3), read(2), stat(2), or realloc(3). so many possibilities, so little time. π
π SEE ALSO π
ferror(3), fgets(3), fgetwln(3bsd), fopen(3), putc(3)
go read them. bestie homework. πβ¨
π HISTORY π
fgetln() first appeared in 4.4BSD. an icon. a legend. the moment. π
Debian Β· April 19, 1994 Β· fgetln(3bsd) β that's the whole page bestie, tysm for reading, ily, go close your streams π«Άππ
π¦ 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