From: Christos Zoulas Date: Tue, 16 Sep 2014 17:25:52 +0000 (+0000) Subject: sync with NetBSD's tools. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ac27b105811fb5d14d6213b4d142d92b7603b03;p=file sync with NetBSD's tools. --- diff --git a/src/getline.c b/src/getline.c index de447628..73ee513c 100644 --- a/src/getline.c +++ b/src/getline.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */ +/* $NetBSD: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -52,11 +52,14 @@ getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) for (ptr = *buf, eptr = *buf + *bufsiz;;) { int c = fgetc(fp); if (c == -1) { - *ptr = '\0'; - 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) {