diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2020-03-02 05:43:45 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2020-03-26 07:42:53 +0000 |
commit | cd62a92d4a964bfe61d35ba2301b69e65e22a509 (patch) | |
tree | 8e346d9037f7c654ffe58ed0d5e27f34025dd672 /usr/src/lib/libc/port/stdio/setvbuf.c | |
parent | 1470234269f4edea4cbf270cb2475e4988b788d5 (diff) | |
download | illumos-joyent-cd62a92d4a964bfe61d35ba2301b69e65e22a509.tar.gz |
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 <john.levon@joyent.com>
Reviewed by: Yuri Pankov <ypankov@fastmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libc/port/stdio/setvbuf.c')
-rw-r--r-- | usr/src/lib/libc/port/stdio/setvbuf.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/usr/src/lib/libc/port/stdio/setvbuf.c b/usr/src/lib/libc/port/stdio/setvbuf.c index a6e63e09f7..936466f893 100644 --- a/usr/src/lib/libc/port/stdio/setvbuf.c +++ b/usr/src/lib/libc/port/stdio/setvbuf.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" @@ -47,7 +45,7 @@ setvbuf(FILE *iop, char *abuf, int type, size_t size) Uchar *temp; int sflag = iop->_flag & _IOMYBUF; rmutex_t *lk; - int fd = GET_FD(iop); + int fd = _get_fd(iop); FLOCKFILE(lk, iop); iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); @@ -55,17 +53,14 @@ setvbuf(FILE *iop, char *abuf, int type, size_t size) /* note that the flags are the same as the possible values for type */ case _IONBF: iop->_flag |= _IONBF; /* file is unbuffered */ -#ifndef _STDIO_ALLOCATE - if (fd < 2) { + if (fd == 0 || fd == 1) { /* use special buffer for std{in,out} */ buf = (fd == 0) ? _sibuf : _sobuf; size = BUFSIZ; - } else /* needed for ifdef */ -#endif - if (fd < _NFILE) { + } else if (fd >= 2 && fd < _NFILE) { buf = _smbuf[fd]; size = _SMBFSZ - PUSHBACK; - } else + } else { if ((buf = malloc(_SMBFSZ * sizeof (Uchar))) != NULL) { iop->_flag |= _IOMYBUF; size = _SMBFSZ - PUSHBACK; @@ -73,6 +68,7 @@ setvbuf(FILE *iop, char *abuf, int type, size_t size) FUNLOCKFILE(lk); return (EOF); } + } break; case _IOLBF: case _IOFBF: |