summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-07-23 14:57:15 +0000
committerpfg <pfg@FreeBSD.org>2014-07-23 14:57:15 +0000
commit821a9bf071f81e75821e47af39948c78cf34a8c6 (patch)
tree5ebd0059a8f4fb6fc07884df9380060ccc6107d0 /lib/libutil
parent632785a0953e75254e753f43e6867019088feb2e (diff)
downloadFreeBSD-src-821a9bf071f81e75821e47af39948c78cf34a8c6.zip
FreeBSD-src-821a9bf071f81e75821e47af39948c78cf34a8c6.tar.gz
fparseln(3): Update from NetBSD sources.
-fix a condition so that fparseln() doesn't report spurious empty lines eg after 2 comment lines, or on EOF after a single comment line -no escape character means no escaped characters modify the previous fix so that no pointless realloc()s are done in the case of multiple empty continuation lines, and comment the code to make the logics obvious fparseln is now part of libc in NetBSD so this changes the previous revision numbering. Obtained from: NetBSD (CVS Rev. 1.6-1.7) MFC after: 2 weeks
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/fparseln.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libutil/fparseln.c b/lib/libutil/fparseln.c
index 0624f0e..d03357e 100644
--- a/lib/libutil/fparseln.c
+++ b/lib/libutil/fparseln.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fparseln.c,v 1.9 1999/09/20 04:48:06 lukem Exp $ */
+/* $NetBSD: fparseln.c,v 1.7 2007/03/08 19:57:53 drochner Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@@ -59,7 +59,7 @@ isescaped(const char *sp, const char *p, int esc)
/* No escape character */
if (esc == '\0')
- return 1;
+ return 0;
/* Count the number of escape characters that precede ours */
for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
@@ -135,13 +135,19 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
cp = &ptr[s - 1];
if (*cp == con && !isescaped(ptr, cp, esc)) {
- s--; /* forget escape */
+ s--; /* forget continuation char */
cnt = 1;
}
}
- if (s == 0 && buf != NULL)
- continue;
+ if (s == 0) {
+ /*
+ * nothing to add, skip realloc except in case
+ * we need a minimal buf to return an empty line
+ */
+ if (cnt || buf != NULL)
+ continue;
+ }
if ((cp = realloc(buf, len + s + 1)) == NULL) {
free(buf);
OpenPOWER on IntegriCloud