Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdio Don't adjust the buffers when write returns 0...



details:   https://anonhg.NetBSD.org/src/rev/61eed9a71eb2
branches:  trunk
changeset: 1022203:61eed9a71eb2
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jul 09 09:24:16 2021 +0000

description:
Don't adjust the buffers when write returns 0. This happens with fmemopen
and other synthetic write functions. This fixes the unit-tests for fmemopen,
but adjusting should be the right behavior for all cases?

diffstat:

 lib/libc/stdio/fflush.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (37 lines):

diff -r 7a4eb2359fd1 -r 61eed9a71eb2 lib/libc/stdio/fflush.c
--- a/lib/libc/stdio/fflush.c   Fri Jul 09 06:37:11 2021 +0000
+++ b/lib/libc/stdio/fflush.c   Fri Jul 09 09:24:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $     */
+/*     $NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)fflush.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fflush.c,v 1.22 2021/07/08 15:44:44 christos Exp $");
+__RCSID("$NetBSD: fflush.c,v 1.23 2021/07/09 09:24:16 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -107,7 +107,9 @@
 
        for (; n > 0; n -= t, p += t) {
                t = (*fp->_write)(fp->_cookie, (char *)p, n);
-               if (t <= 0) {
+               if (t == 0)
+                       goto out;
+               if (t < 0) {
                        /* Reset _p and _w. */
                        if (p > fp->_p) {
                                /* Some was written. */
@@ -116,6 +118,7 @@
                        fp->_p += n;
                        if ((fp->_flags & (__SLBF | __SNBF)) == 0)
                                fp->_w -= n;
+out:
                        fp->_flags |= __SERR;
                        return EOF;
                }



Home | Main Index | Thread Index | Old Index