Lines Matching defs:iop

67 fclose(FILE *iop)
71 if(iop == NULL)
73 if(iop->_flag & (_IOREAD | _IOWRT | _IORW)
74 && (iop->_flag & _IOSTRG) == 0) {
75 rtn = (iop->_flag & _IONBF)? 0: fflush(iop);
76 if(close(fileno(iop)) < 0)
79 if(iop->_flag & _IOMYBUF) {
80 free((char*)iop->_base);
81 iop->_base = NULL;
83 iop->_flag = 0;
84 iop->_cnt = 0;
85 iop->_ptr = iop->_base;
86 iop->_bufsiz = 0;
98 fflush(FILE *iop)
100 if (!(iop->_flag & _IOWRT)) {
101 if ((iop->_base != NULL) && iop->_cnt) {
102 lseek(iop->_file, -(iop->_cnt), SEEK_CUR);
103 iop->_cnt = 0;
107 while(!(iop->_flag & _IONBF) && (iop->_flag & _IOWRT) &&
108 (iop->_base != NULL) && (iop->_ptr > iop->_base) )
109 (void) _xflsbuf(iop);
110 return(ferror(iop) ? EOF : 0);
115 * the file is line-buffered, the fact that iop->_cnt has run below zero
119 * buffer is actually full by comparing iop->_ptr to the end of the buffer
120 * iop->_base + iop->_bufsiz. If it is full, or if an output line is
127 _flsbuf(unsigned char c, FILE *iop)
133 if ( (iop->_flag & (_IOLBF | _IOWRT | _IOEOF)) == (_IOLBF | _IOWRT) ) {
134 if ( iop->_ptr >= iop->_base + iop->_bufsiz ) /* if buffer full, */
136 if ( (*iop->_ptr++ = c) != '\n' )
138 return(_xflsbuf(iop) == EOF ? EOF : c);
141 if ( (iop->_flag & (_IONBF | _IOWRT | _IOEOF)) == (_IONBF | _IOWRT) ) {
143 iop->_cnt = 0;
144 if (write(fileno(iop), (char *) &c1, 1) == 1)
146 iop->_flag |= _IOERR;
152 if (_WRTCHK(iop)) /* is writing legitimate? */
154 } while ( (iop->_flag & (_IONBF | _IOLBF)) );
157 (void) _xflsbuf(iop); /* full buffer: flush buffer */
158 (void) putc((char) c, iop); /* then put "c" in newly emptied buf */
160 return( ferror(iop) ? EOF : c);
165 * buffer delimited by iop->_base and iop->_ptr.
166 * iop->_cnt is reset appropriately, but its value on entry to _xflsbuf
183 _xflsbuf(FILE *iop)
188 n = iop->_ptr - (base = iop->_base);
189 iop->_ptr = base;
190 iop->_cnt = (iop->_flag &(_IONBF | _IOLBF)) ? 0 : iop->_bufsiz;
191 _BUFSYNC(iop);
192 if (n > 0 && n != write(fileno(iop),(char*)base,(unsigned)n) ) {
193 iop->_flag |= _IOERR;
201 * to the specified device. If it is, _wrtchk sets flags in iop->_flag for
207 _wrtchk(FILE *iop)
209 if ( (iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT ) {
210 if (!(iop->_flag & (_IOWRT | _IORW)))
212 iop->_flag = iop->_flag & ~_IOEOF | _IOWRT; /* fix flags */
214 if (iop->_flag & _IOSTRG)
216 if (iop->_base == NULL) /* this is first I/O to file--get buffer */
217 _findbuf(iop);
218 if (iop->_ptr == iop->_base && !(iop->_flag & (_IONBF | _IOLBF)) ) {
219 iop->_cnt = iop->_bufsiz; /* first write since seek--set cnt */
220 _BUFSYNC(iop);
226 * _findbuf, called only when iop->_base == NULL, locates a predefined buffer
228 * the _IOMYBUF flag is set in iop->_flag.
232 _findbuf(FILE *iop)
234 int fno = fileno(iop); /* file number */
239 if (iop->_flag & _IONBF) {
240 iop->_base = _smbuf[fno];
241 iop->_bufsiz = _SBFSIZ;
245 iop->_flag |= _IOLBF;
255 if ((iop->_base = (unsigned char *) malloc(size+8)) != NULL) {
257 iop->_flag |= _IOMYBUF;
258 iop->_bufsiz = size;
261 iop->_base = _smbuf[fno];
262 iop->_bufsiz = _SBFSIZ;
263 iop->_flag &= ~_IOLBF;
264 iop->_flag |= _IONBF;
267 iop->_ptr = iop->_base;
272 * which occur in between the decrementing of iop->_cnt and the incrementing
273 * of iop->_ptr, or in other contexts as well, may upset the synchronization
274 * of iop->_cnt and iop->ptr. If this happens, calling _bufsync should
282 _bufsync(FILE *iop)
285 unsigned char *bufend = iop->_base + iop->_bufsiz;
287 if ((spaceleft = bufend - iop->_ptr) < 0)
288 iop->_ptr = bufend;
289 else if (spaceleft < iop->_cnt)
290 iop->_cnt = spaceleft;