fparseln(3bsd)
π fparseln β like, the manual page for fparseln(3bsd) π
okay bestie, sit down, hydrate, because today we're learning about fparseln β the little function that goes "hey, gimme the next logical line from this stream" and then actually does it. no cap. it's from section 3bsd, and it is serving.
β¨ LIBRARY β¨
it lives in the Utility functions from BSD systems, which is libbsd, and you link it with -lbsd. iconic. π₯
πΈ SYNOPSIS πΈ
#include <stdio.h>
(See libbsd(7) for include usage.)
char *
fparseln(FILE *stream, size_t *len, size_t *lineno, const char delim[3],
int flags);
π«Ά heads up: the#include <stdio.h>line comes with a lil footnote β checklibbsd(7)for include usage. it's giving "read the fine print, babe".
π DESCRIPTION π
so. fparseln() returns a pointer to the next logical line from the stream you passed it. the string is NUL terminated, and it gets dynamically allocated on every single invocation β like a fresh fit every time. and because it's your new toy, it is 100% your responsibility to free() that pointer. bestie, free your pointers. i'm begging. π
by default, if a character is escaped, both it and the preceding escape character will show up in the returned string. like, both of them. just hanging out. but!! there are flags that alter this behaviour, so if you want that escape character gone, keep reading. π
now the arguments, one by one, no skipping:
streamβ the stream to read from. that's it, that's the vibe. the source of the tea. βlenβ if it's notNULL, the length of the string gets stored in the memory location it points to. so pass a pointer and it'll tell you how long your line is. πlinenoβ if it's notNULL, the value at the memory location it points to gets incremented by the number of lines actually read from the file. yes, actually read β so no, it's not just "+1 per call", it counts the real lines it chomped through. πdelimβ this one contains the escape, continuation, and comment characters. important rules:- if a character is
NUL, then processing for that character is disabled. gone. off. not invited. - if
delimisNULL, all the characters default to the values listed below. easy.
- if a character is
the contents of delim go like this:
delim[0]β the escape character, which defaults to\, is used to remove any special meaning from the next character.delim[1]β the continuation character, which defaults to\, is used to indicate that the next line should be concatenated with the current one β but only if this character is the last character on the current line and it is not escaped. two conditions, both required, no exceptions. β¨delim[2]β the comment character, which defaults to#, and if it's not escaped, it indicates the beginning of a comment that extends until the end of the current line. bye to everything after it. π
flagsβ if non-zero, it alters the operation offparseln(). you can or them together, and here's the full menu, no substitutions:FPARSELN_UNESCCOMMβ remove escape preceding an escaped comment.FPARSELN_UNESCCONTβ remove escape preceding an escaped continuation.FPARSELN_UNESCESCβ remove escape preceding an escaped escape.FPARSELN_UNESCRESTβ remove escape preceding any other character.FPARSELN_UNESCALLβ all of the above. the whole set. the full bundle. slay. π
π RETURN VALUES π
- if everything goes well, you get a pointer to the parsed line. π
- otherwise, you get
NULL. π
and here's the lore: fparseln() uses getline(3) internally, so every single error condition that applies to getline(3) also applies to fparseln(). plus, in addition, fparseln() may set errno to [ENOMEM] and return NULL if it runs out of memory. so if your memory said "no <3", you get ENOMEM and a NULL. π«
π¦ SEE ALSO π¦
β HISTORY β
the fparseln() function first appeared in NetBSD 1.4 and FreeBSD 4.0. vintage, honestly. a classic. π
and that's the whole page, bestie!! this lil rewrite came to you from Debian, dated November 30, 2002 β so if you're reading this, mwah, thanks for coming to my ted talk, now go free() your pointers π
β¨π«Ά
π¦ 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 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
- 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) 1997 Christos Zoulas. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms