fgetln(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 #include situation has ✨lore✨ β€” go read libbsd(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 argument stream is 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