Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdio Account for partial writes when interrupted (...



details:   https://anonhg.NetBSD.org/src/rev/6458d0ec9f24
branches:  trunk
changeset: 1022115:6458d0ec9f24
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jul 05 07:26:00 2021 +0000

description:
Account for partial writes when interrupted (from FreeBSD).

diffstat:

 lib/libc/stdio/fflush.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (42 lines):

diff -r 25bcbec8f1db -r 6458d0ec9f24 lib/libc/stdio/fflush.c
--- a/lib/libc/stdio/fflush.c   Sun Jul 04 22:42:35 2021 +0000
+++ b/lib/libc/stdio/fflush.c   Mon Jul 05 07:26:00 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $     */
+/*     $NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 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.18 2012/03/27 15:05:42 christos Exp $");
+__RCSID("$NetBSD: fflush.c,v 1.19 2021/07/05 07:26:00 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,6 +45,8 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
+
 #include "reentrant.h"
 #include "local.h"
 
@@ -106,6 +108,14 @@
        for (; n > 0; n -= t, p += t) {
                t = (*fp->_write)(fp->_cookie, (char *)p, n);
                if (t <= 0) {
+                       /* Reset _p and _w. */
+                       if (p > fp->_p) {
+                               /* Some was written. */
+                               memmove(fp->_p, p, n);
+                               fp->_p += n;
+                               if ((fp->_flags & (__SLBF | __SNBF)) == 0)
+                                       fp->_w -= n;
+                       }
                        fp->_flags |= __SERR;
                        return EOF;
                }



Home | Main Index | Thread Index | Old Index