Download raw body.
fparseln(3) and newlines
This bugged me the last two times I looked at this function.
I don't see why we should be looking for another "newline" character.
getdelim(3) could let us use one single alternate character, but given
the signature of fparseln(3) I don't see us shoehorning that "feature"
that probably nobody would find useful.
So here's a diff to strip the related code and XXX. ok?
Index: fparseln.c
===================================================================
RCS file: /cvs/src/lib/libutil/fparseln.c,v
diff -u -p -r1.8 fparseln.c
--- fparseln.c 4 Jan 2023 13:00:11 -0000 1.8
+++ fparseln.c 1 Nov 2025 15:15:05 -0000
@@ -66,7 +66,7 @@ fparseln(FILE *fp, size_t *size, size_t
int flags)
{
static const char dstr[3] = { '\\', '\\', '#' };
- char *buf = NULL, *ptr, *cp, esc, con, nl, com;
+ char *buf = NULL, *ptr, *cp, esc, con, com;
size_t s, len = 0;
int cnt = 1;
@@ -77,12 +77,6 @@ fparseln(FILE *fp, size_t *size, size_t
con = str[1];
com = str[2];
- /*
- * XXX: it would be cool to be able to specify the newline character,
- * but unfortunately, fgetln does not let us
- */
- nl = '\n';
-
while (cnt) {
cnt = 0;
@@ -101,10 +95,10 @@ fparseln(FILE *fp, size_t *size, size_t
}
}
- if (s && nl) { /* Check and eliminate newlines */
+ if (s) { /* Check and eliminate newlines */
cp = &ptr[s - 1];
- if (*cp == nl)
+ if (*cp == '\n')
s--; /* forget newline */
}
--
jca
fparseln(3) and newlines