Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdio Obey EINTR and return immediately adjusting f...



details:   https://anonhg.NetBSD.org/src/rev/5d503cbdc475
branches:  trunk
changeset: 984447:5d503cbdc475
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 08 09:06:51 2021 +0000

description:
Obey EINTR and return immediately adjusting for unwritten. From RVP

diffstat:

 lib/libc/stdio/fflush.c  |  14 +++++---------
 lib/libc/stdio/fvwrite.c |  27 +++++++++++++--------------
 2 files changed, 18 insertions(+), 23 deletions(-)

diffs (109 lines):

diff -r 8e42d7c1d450 -r 5d503cbdc475 lib/libc/stdio/fflush.c
--- a/lib/libc/stdio/fflush.c   Thu Jul 08 05:18:49 2021 +0000
+++ b/lib/libc/stdio/fflush.c   Thu Jul 08 09:06:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fflush.c,v 1.20 2021/07/06 14:22:16 christos Exp $     */
+/*     $NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 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.20 2021/07/06 14:22:16 christos Exp $");
+__RCSID("$NetBSD: fflush.c,v 1.21 2021/07/08 09:06:51 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -108,18 +108,14 @@
        for (; n > 0; n -= t, p += t) {
                t = (*fp->_write)(fp->_cookie, (char *)p, n);
                if (t < 0) {
-                       if (errno == EINTR) {
-                               t = 0;
-                               continue;
-                       }
                        /* 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->_p += n;
+                       if ((fp->_flags & (__SLBF | __SNBF)) == 0)
+                               fp->_w -= n;
                        fp->_flags |= __SERR;
                        return EOF;
                }
diff -r 8e42d7c1d450 -r 5d503cbdc475 lib/libc/stdio/fvwrite.c
--- a/lib/libc/stdio/fvwrite.c  Thu Jul 08 05:18:49 2021 +0000
+++ b/lib/libc/stdio/fvwrite.c  Thu Jul 08 09:06:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $    */
+/*     $NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $    */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)fvwrite.c  8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fvwrite.c,v 1.26 2021/07/06 14:22:16 christos Exp $");
+__RCSID("$NetBSD: fvwrite.c,v 1.27 2021/07/08 09:06:51 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -99,12 +99,14 @@
        }
 #define WRITE(nw) \
        w = (*fp->_write)(fp->_cookie, p, nw); \
-       if (w < 0) { \
-               if (errno != EINTR) \
-                       goto err; \
-               w = 0; \
-       } else \
-               w = w
+       if (w <= 0) \
+               goto err
+#define FLUSH(nw) \
+       if (fflush(fp)) { \
+               fp->_p -= nw;   /* rewind unwritten */ \
+               goto err; \
+       }
+
        if (fp->_flags & __SNBF) {
                /*
                 * Unbuffered: write up to BUFSIZ bytes at a time.
@@ -162,8 +164,7 @@
                                COPY(w);
                                /* fp->_w -= w; */ /* unneeded */
                                fp->_p += w;
-                               if (fflush(fp))
-                                       goto err;
+                               FLUSH(w);
                        } else if (len >= (size_t)(w = fp->_bf._size)) {
                                /* write directly */
                                WRITE((size_t)w);
@@ -200,8 +201,7 @@
                                COPY(w);
                                /* fp->_w -= w; */
                                fp->_p += w;
-                               if (fflush(fp))
-                                       goto err;
+                               FLUSH(w);
                        } else if (s >= (w = fp->_bf._size)) {
                                WRITE((size_t)w);
                        } else {
@@ -212,8 +212,7 @@
                        }
                        if ((nldist -= w) == 0) {
                                /* copied the newline: flush and forget */
-                               if (fflush(fp))
-                                       goto err;
+                               FLUSH(w);
                                nlknown = 0;
                        }
                        p += w;



Home | Main Index | Thread Index | Old Index