Obey EINTR and return immediately adjusting for unwritten. From RVP
This commit is contained in:
parent
19f514055a
commit
f280538df1
|
@ -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 @@ __sflush(FILE *fp)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||
}
|
||||
#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 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||
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 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||
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 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||
}
|
||||
if ((nldist -= w) == 0) {
|
||||
/* copied the newline: flush and forget */
|
||||
if (fflush(fp))
|
||||
goto err;
|
||||
FLUSH(w);
|
||||
nlknown = 0;
|
||||
}
|
||||
p += w;
|
||||
|
|
Loading…
Reference in New Issue