]> granicus.if.org Git - file/commitdiff
sync with NetBSD's tools.
authorChristos Zoulas <christos@zoulas.com>
Tue, 16 Sep 2014 17:25:52 +0000 (17:25 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 16 Sep 2014 17:25:52 +0000 (17:25 +0000)
src/getline.c

index de44762827339d7946881e50a65b77c88fe9ae33..73ee513c6bddf6ee9db5d00f14941f0a56f766bd 100644 (file)
@@ -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) {