[PATCH] expand on API guarantee
Thorsten Glaser
tg at mirbsd.org
Thu Dec 10 09:07:25 PST 2009
OpenBSD has begun using the API guarantee that *len is not 0 if
the fgetln(3) return value is not NULL; document this explicitly
in the manpage and add a comment to the function implementation
that this doesn’t need to be checked because getdelim/getline have
similar guarantees.
Signed-off-by: Thorsten Glaser <tg at mirbsd.org>
---
man/fgetln.3 | 2 +-
src/fgetln.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/man/fgetln.3 b/man/fgetln.3
index d483c09..c01d1ef 100644
--- a/man/fgetln.3
+++ b/man/fgetln.3
@@ -54,7 +54,7 @@ character.
The length of the line, including the final newline,
is stored in the memory location to which
.Fa len
-points.
+points and is guaranteed to be greater than 0 upon successful completion.
(Note, however, that if the line is the last
in a file that does not end in a newline,
the returned text will not contain a newline.)
diff --git a/src/fgetln.c b/src/fgetln.c
index 6e3d000..0225ae2 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -39,6 +39,7 @@ fgetln (FILE *stream, size_t *len)
ssize_t nread;
nread = getline(&line, &line_len, stream);
+ /* note: the getdelim/getline API ensures nread != 0 */
if (nread == -1) {
*len = 0;
return NULL;
@@ -48,4 +49,3 @@ fgetln (FILE *stream, size_t *len)
}
}
#endif
-
--
1.5.4.3
More information about the libbsd
mailing list