diff options
Diffstat (limited to 'usr/src/lib/libc/port/stdio/setbuf.c')
-rw-r--r-- | usr/src/lib/libc/port/stdio/setbuf.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/usr/src/lib/libc/port/stdio/setbuf.c b/usr/src/lib/libc/port/stdio/setbuf.c index 78c4c8cc76..10eb21d5b5 100644 --- a/usr/src/lib/libc/port/stdio/setbuf.c +++ b/usr/src/lib/libc/port/stdio/setbuf.c @@ -25,9 +25,11 @@ */ /* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright 2020 Robert Mustacchi + */ #include "lint.h" #include "file64.h" @@ -39,41 +41,37 @@ #include <synch.h> #include "stdiom.h" - void setbuf(FILE *iop, char *abuf) { Uchar *buf = (Uchar *)abuf; - int fno = GET_FD(iop); /* file number */ + int fno = _get_fd(iop); /* file number */ int size = BUFSIZ - _SMBFSZ; Uchar *temp; rmutex_t *lk; FLOCKFILE(lk, iop); - if ((iop->_base != 0) && (iop->_flag & _IOMYBUF)) + if ((iop->_base != NULL) && (iop->_flag & _IOMYBUF)) free((char *)iop->_base - PUSHBACK); iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); - if (buf == 0) { + if (buf == NULL) { iop->_flag |= _IONBF; -#ifndef _STDIO_ALLOCATE - if (fno < 2) { + if (fno == 0 || fno == 1) { /* use special buffer for std{in,out} */ buf = (fno == 0) ? _sibuf : _sobuf; - } else /* needed for ifndef */ -#endif - if (fno < _NFILE) { + } else if (fno >= 2 && fno < _NFILE) { buf = _smbuf[fno]; size = _SMBFSZ - PUSHBACK; - } else - if ((buf = (Uchar *)malloc(_SMBFSZ * sizeof (Uchar))) != 0) { + } else if ((buf = (Uchar *)malloc(_SMBFSZ * + sizeof (Uchar))) != NULL) { iop->_flag |= _IOMYBUF; size = _SMBFSZ - PUSHBACK; } } else { /* regular buffered I/O, standard buffer size */ - if (isatty(fno)) + if (fno != -1 && isatty(fno)) iop->_flag |= _IOLBF; } - if (buf == 0) { + if (buf == NULL) { FUNLOCKFILE(lk); return; /* malloc() failed */ } |