Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tools/compat Fix problem reading the last line when it did n...
details: https://anonhg.NetBSD.org/src/rev/41da2f89e48d
branches: trunk
changeset: 332333:41da2f89e48d
user: christos <christos%NetBSD.org@localhost>
date: Tue Sep 16 17:23:50 2014 +0000
description:
Fix problem reading the last line when it did not contain a delimiter
(Hubert Garavel)
diffstat:
tools/compat/getline.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diffs (28 lines):
diff -r 17b292755784 -r 41da2f89e48d tools/compat/getline.c
--- a/tools/compat/getline.c Tue Sep 16 15:08:58 2014 +0000
+++ b/tools/compat/getline.c Tue Sep 16 17:23:50 2014 +0000
@@ -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 @@
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) {
Home |
Main Index |
Thread Index |
Old Index