From cd62a92d4a964bfe61d35ba2301b69e65e22a509 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Mon, 2 Mar 2020 05:43:45 +0000 Subject: 7092 Want support for stdio memory streams 12360 fwrite can loop forever on zero byte write 12392 ftello64 doesn't handle ungetc() correctly when unbuffered Reviewed by: John Levon Reviewed by: Yuri Pankov Approved by: Dan McDonald --- usr/src/lib/libc/port/stdio/fwrite.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'usr/src/lib/libc/port/stdio/fwrite.c') diff --git a/usr/src/lib/libc/port/stdio/fwrite.c b/usr/src/lib/libc/port/stdio/fwrite.c index db5928f9f4..070354f24b 100644 --- a/usr/src/lib/libc/port/stdio/fwrite.c +++ b/usr/src/lib/libc/port/stdio/fwrite.c @@ -25,9 +25,7 @@ */ /* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include "lint.h" #include "file64.h" @@ -108,9 +106,9 @@ _fwrite_unlocked(const void *ptr, size_t size, size_t count, FILE *iop) bytes = iop->_ptr - iop->_base; data = (char *)iop->_base; - while ((n = write(fileno(iop), data, (size_t)bytes)) - != bytes) { - if (n == -1) { + while ((n = _xwrite(iop, data, (size_t)bytes)) != + bytes) { + if (n <= 0) { if (!cancel_active()) iop->_flag |= _IOERR; return (0); @@ -126,8 +124,8 @@ _fwrite_unlocked(const void *ptr, size_t size, size_t count, FILE *iop) * written is in bytes until the return. * Then it is divided by size to produce items. */ - while ((n = write(fileno(iop), dptr, s)) != s) { - if (n == -1) { + while ((n = _xwrite(iop, dptr, s)) != s) { + if (n <= 0) { if (!cancel_active()) iop->_flag |= _IOERR; return (written / size); -- cgit v1.2.3