Module Name: src
Committed By: christos
Date: Tue Sep 16 17:23:50 UTC 2014
Modified Files:
src/tools/compat: getline.c
Log Message:
Fix problem reading the last line when it did not contain a delimiter
(Hubert Garavel)
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tools/compat/getline.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tools/compat/getline.c
diff -u src/tools/compat/getline.c:1.1 src/tools/compat/getline.c:1.2
--- src/tools/compat/getline.c:1.1 Sun Mar 20 16:48:57 2011
+++ src/tools/compat/getline.c Tue Sep 16 13:23:50 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: getline.c,v 1.1 2011/03/20 20:48:57 christos Exp $ */
+/* $NetBSD: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -59,10 +59,14 @@ getdelim(char **buf, size_t *bufsiz, int
for (ptr = *buf, eptr = *buf + *bufsiz;;) {
int c = fgetc(fp);
if (c == -1) {
- if (feof(fp))
- return ptr == *buf ? -1 : ptr - *buf;
- else
- return -1;
+ if (feof(fp)) {
+ ssize_t diff = (ssize_t)(ptr - *buf);
+ if (diff != 0) {
+ *ptr = '\0';
+ return diff;
+ }
+ }
+ return -1;
}
*ptr++ = c;
if (c == delimiter) {