Lines Matching refs:stream

99 static void jas_stream_destroy(jas_stream_t *stream);
101 static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,
150 jas_stream_t *stream; in jas_stream_create() local
152 if (!(stream = jas_malloc(sizeof(jas_stream_t)))) { in jas_stream_create()
155 stream->openmode_ = 0; in jas_stream_create()
156 stream->bufmode_ = 0; in jas_stream_create()
157 stream->flags_ = 0; in jas_stream_create()
158 stream->bufbase_ = 0; in jas_stream_create()
159 stream->bufstart_ = 0; in jas_stream_create()
160 stream->bufsize_ = 0; in jas_stream_create()
161 stream->ptr_ = 0; in jas_stream_create()
162 stream->cnt_ = 0; in jas_stream_create()
163 stream->ops_ = 0; in jas_stream_create()
164 stream->obj_ = 0; in jas_stream_create()
165 stream->rwcnt_ = 0; in jas_stream_create()
166 stream->rwlimit_ = -1; in jas_stream_create()
168 return stream; in jas_stream_create()
173 jas_stream_t *stream; in jas_stream_memopen() local
176 if (!(stream = jas_stream_create())) { in jas_stream_memopen()
182 stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY; in jas_stream_memopen()
187 jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); in jas_stream_memopen()
190 stream->ops_ = &jas_stream_memops; in jas_stream_memopen()
194 jas_stream_destroy(stream); in jas_stream_memopen()
197 stream->obj_ = (void *) obj; in jas_stream_memopen()
219 jas_stream_close(stream); in jas_stream_memopen()
233 return stream; in jas_stream_memopen()
238 jas_stream_t *stream; in jas_stream_fopen() local
243 if (!(stream = jas_stream_create())) { in jas_stream_fopen()
248 stream->openmode_ = jas_strtoopenmode(mode); in jas_stream_fopen()
251 if ((stream->openmode_ & JAS_STREAM_READ) && in jas_stream_fopen()
252 (stream->openmode_ & JAS_STREAM_WRITE)) { in jas_stream_fopen()
254 } else if (stream->openmode_ & JAS_STREAM_READ) { in jas_stream_fopen()
256 } else if (stream->openmode_ & JAS_STREAM_WRITE) { in jas_stream_fopen()
261 if (stream->openmode_ & JAS_STREAM_APPEND) { in jas_stream_fopen()
264 if (stream->openmode_ & JAS_STREAM_BINARY) { in jas_stream_fopen()
267 if (stream->openmode_ & JAS_STREAM_CREATE) { in jas_stream_fopen()
273 jas_stream_destroy(stream); in jas_stream_fopen()
279 stream->obj_ = (void *) obj; in jas_stream_fopen()
282 stream->ops_ = &jas_stream_fileops; in jas_stream_fopen()
286 jas_stream_destroy(stream); in jas_stream_fopen()
291 jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); in jas_stream_fopen()
293 return stream; in jas_stream_fopen()
298 jas_stream_t *stream; in jas_stream_freopen() local
305 if (!(stream = jas_stream_create())) { in jas_stream_freopen()
310 stream->openmode_ = jas_strtoopenmode(mode); in jas_stream_freopen()
313 if ((stream->openmode_ & JAS_STREAM_READ) && in jas_stream_freopen()
314 (stream->openmode_ & JAS_STREAM_WRITE)) { in jas_stream_freopen()
316 } else if (stream->openmode_ & JAS_STREAM_READ) { in jas_stream_freopen()
318 } else if (stream->openmode_ & JAS_STREAM_WRITE) { in jas_stream_freopen()
323 if (stream->openmode_ & JAS_STREAM_APPEND) { in jas_stream_freopen()
326 if (stream->openmode_ & JAS_STREAM_BINARY) { in jas_stream_freopen()
329 if (stream->openmode_ & JAS_STREAM_CREATE) { in jas_stream_freopen()
333 stream->obj_ = JAS_CAST(void *, fp); in jas_stream_freopen()
336 stream->ops_ = &jas_stream_sfileops; in jas_stream_freopen()
339 jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); in jas_stream_freopen()
341 return stream; in jas_stream_freopen()
346 jas_stream_t *stream; in jas_stream_tmpfile() local
350 if (!(stream = jas_stream_create())) { in jas_stream_tmpfile()
356 stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY; in jas_stream_tmpfile()
360 jas_stream_destroy(stream); in jas_stream_tmpfile()
365 stream->obj_ = obj; in jas_stream_tmpfile()
376 jas_stream_destroy(stream); in jas_stream_tmpfile()
385 jas_stream_destroy(stream); in jas_stream_tmpfile()
393 jas_stream_destroy(stream); in jas_stream_tmpfile()
398 jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); in jas_stream_tmpfile()
400 stream->ops_ = &jas_stream_fileops; in jas_stream_tmpfile()
402 return stream; in jas_stream_tmpfile()
407 jas_stream_t *stream; in jas_stream_fdopen() local
411 if (!(stream = jas_stream_create())) { in jas_stream_fdopen()
416 stream->openmode_ = jas_strtoopenmode(mode); in jas_stream_fdopen()
430 if (stream->openmode_ & JAS_STREAM_BINARY) { in jas_stream_fdopen()
437 jas_stream_destroy(stream); in jas_stream_fdopen()
443 stream->obj_ = (void *) obj; in jas_stream_fdopen()
450 jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); in jas_stream_fdopen()
453 stream->ops_ = &jas_stream_fileops; in jas_stream_fdopen()
455 return stream; in jas_stream_fdopen()
458 static void jas_stream_destroy(jas_stream_t *stream) in jas_stream_destroy() argument
462 if ((stream->bufmode_ & JAS_STREAM_FREEBUF) && stream->bufbase_) { in jas_stream_destroy()
463 jas_free(stream->bufbase_); in jas_stream_destroy()
464 stream->bufbase_ = 0; in jas_stream_destroy()
466 jas_free(stream); in jas_stream_destroy()
469 int jas_stream_close(jas_stream_t *stream) in jas_stream_close() argument
472 jas_stream_flush(stream); in jas_stream_close()
475 (*stream->ops_->close_)(stream->obj_); in jas_stream_close()
477 jas_stream_destroy(stream); in jas_stream_close()
486 int jas_stream_getc_func(jas_stream_t *stream) in jas_stream_getc_func() argument
488 assert(stream->ptr_ - stream->bufbase_ <= stream->bufsize_ + in jas_stream_getc_func()
490 return jas_stream_getc_macro(stream); in jas_stream_getc_func()
493 int jas_stream_putc_func(jas_stream_t *stream, int c) in jas_stream_putc_func() argument
495 assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_); in jas_stream_putc_func()
496 return jas_stream_putc_macro(stream, c); in jas_stream_putc_func()
499 int jas_stream_ungetc(jas_stream_t *stream, int c) in jas_stream_ungetc() argument
501 if (!stream->ptr_ || stream->ptr_ == stream->bufbase_) { in jas_stream_ungetc()
507 stream->flags_ &= ~JAS_STREAM_EOF; in jas_stream_ungetc()
509 --stream->rwcnt_; in jas_stream_ungetc()
510 --stream->ptr_; in jas_stream_ungetc()
511 ++stream->cnt_; in jas_stream_ungetc()
512 *stream->ptr_ = c; in jas_stream_ungetc()
516 int jas_stream_read(jas_stream_t *stream, void *buf, int cnt) in jas_stream_read() argument
526 if ((c = jas_stream_getc(stream)) == EOF) { in jas_stream_read()
536 int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt) in jas_stream_write() argument
545 if (jas_stream_putc(stream, *bufptr) == EOF) { in jas_stream_write()
558 int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...) in jas_stream_printf() argument
566 jas_stream_puts(stream, buf); in jas_stream_printf()
571 int jas_stream_puts(jas_stream_t *stream, const char *s) in jas_stream_puts() argument
574 if (jas_stream_putc_macro(stream, *s) == EOF) { in jas_stream_puts()
582 char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize) in jas_stream_gets() argument
590 if ((c = jas_stream_getc(stream)) == EOF) { in jas_stream_gets()
603 int jas_stream_gobble(jas_stream_t *stream, int n) in jas_stream_gobble() argument
608 if (jas_stream_getc(stream) == EOF) { in jas_stream_gobble()
615 int jas_stream_pad(jas_stream_t *stream, int n, int c) in jas_stream_pad() argument
620 if (jas_stream_putc(stream, c) == EOF) in jas_stream_pad()
630 int jas_stream_isseekable(jas_stream_t *stream) in jas_stream_isseekable() argument
632 if (stream->ops_ == &jas_stream_memops) { in jas_stream_isseekable()
634 } else if (stream->ops_ == &jas_stream_fileops) { in jas_stream_isseekable()
635 if ((*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR) < 0) { in jas_stream_isseekable()
644 int jas_stream_rewind(jas_stream_t *stream) in jas_stream_rewind() argument
646 return jas_stream_seek(stream, 0, SEEK_SET); in jas_stream_rewind()
649 long jas_stream_seek(jas_stream_t *stream, long offset, int origin) in jas_stream_seek() argument
654 assert(!((stream->bufmode_ & JAS_STREAM_RDBUF) && (stream->bufmode_ & in jas_stream_seek()
658 stream->flags_ &= ~JAS_STREAM_EOF; in jas_stream_seek()
660 if (stream->bufmode_ & JAS_STREAM_RDBUF) { in jas_stream_seek()
662 offset -= stream->cnt_; in jas_stream_seek()
664 } else if (stream->bufmode_ & JAS_STREAM_WRBUF) { in jas_stream_seek()
665 if (jas_stream_flush(stream)) { in jas_stream_seek()
669 stream->cnt_ = 0; in jas_stream_seek()
670 stream->ptr_ = stream->bufstart_; in jas_stream_seek()
671 stream->bufmode_ &= ~(JAS_STREAM_RDBUF | JAS_STREAM_WRBUF); in jas_stream_seek()
673 if ((newpos = (*stream->ops_->seek_)(stream->obj_, offset, origin)) in jas_stream_seek()
681 long jas_stream_tell(jas_stream_t *stream) in jas_stream_tell() argument
686 if (stream->bufmode_ & JAS_STREAM_RDBUF) { in jas_stream_tell()
687 adjust = -stream->cnt_; in jas_stream_tell()
688 } else if (stream->bufmode_ & JAS_STREAM_WRBUF) { in jas_stream_tell()
689 adjust = stream->ptr_ - stream->bufstart_; in jas_stream_tell()
694 if ((offset = (*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR)) < 0) { in jas_stream_tell()
705 static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf, in jas_stream_initbuf() argument
710 assert(!stream->bufbase_); in jas_stream_initbuf()
717 if ((stream->bufbase_ = jas_malloc(JAS_STREAM_BUFSIZE + in jas_stream_initbuf()
719 stream->bufmode_ |= JAS_STREAM_FREEBUF; in jas_stream_initbuf()
720 stream->bufsize_ = JAS_STREAM_BUFSIZE; in jas_stream_initbuf()
724 stream->bufbase_ = stream->tinybuf_; in jas_stream_initbuf()
725 stream->bufsize_ = 1; in jas_stream_initbuf()
732 stream->bufbase_ = JAS_CAST(uchar *, buf); in jas_stream_initbuf()
733 stream->bufsize_ = bufsize - JAS_STREAM_MAXPUTBACK; in jas_stream_initbuf()
740 stream->bufbase_ = stream->tinybuf_; in jas_stream_initbuf()
741 stream->bufsize_ = 1; in jas_stream_initbuf()
743 stream->bufstart_ = &stream->bufbase_[JAS_STREAM_MAXPUTBACK]; in jas_stream_initbuf()
744 stream->ptr_ = stream->bufstart_; in jas_stream_initbuf()
745 stream->cnt_ = 0; in jas_stream_initbuf()
746 stream->bufmode_ |= bufmode & JAS_STREAM_BUFMODEMASK; in jas_stream_initbuf()
753 int jas_stream_flush(jas_stream_t *stream) in jas_stream_flush() argument
755 if (stream->bufmode_ & JAS_STREAM_RDBUF) { in jas_stream_flush()
758 return jas_stream_flushbuf(stream, EOF); in jas_stream_flush()
761 int jas_stream_fillbuf(jas_stream_t *stream, int getflag) in jas_stream_fillbuf() argument
766 if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) { in jas_stream_fillbuf()
771 if ((stream->openmode_ & JAS_STREAM_READ) == 0) { in jas_stream_fillbuf()
778 assert((stream->bufmode_ & JAS_STREAM_WRBUF) == 0); in jas_stream_fillbuf()
780 assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_); in jas_stream_fillbuf()
783 stream->bufmode_ |= JAS_STREAM_RDBUF; in jas_stream_fillbuf()
786 stream->ptr_ = stream->bufstart_; in jas_stream_fillbuf()
787 if ((stream->cnt_ = (*stream->ops_->read_)(stream->obj_, in jas_stream_fillbuf()
788 (char *) stream->bufstart_, stream->bufsize_)) <= 0) { in jas_stream_fillbuf()
789 if (stream->cnt_ < 0) { in jas_stream_fillbuf()
790 stream->flags_ |= JAS_STREAM_ERR; in jas_stream_fillbuf()
792 stream->flags_ |= JAS_STREAM_EOF; in jas_stream_fillbuf()
794 stream->cnt_ = 0; in jas_stream_fillbuf()
798 assert(stream->cnt_ > 0); in jas_stream_fillbuf()
800 c = (getflag) ? jas_stream_getc2(stream) : (*stream->ptr_); in jas_stream_fillbuf()
805 int jas_stream_flushbuf(jas_stream_t *stream, int c) in jas_stream_flushbuf() argument
811 if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) { in jas_stream_flushbuf()
816 if ((stream->openmode_ & (JAS_STREAM_WRITE | JAS_STREAM_APPEND)) == 0) { in jas_stream_flushbuf()
821 assert(!(stream->bufmode_ & JAS_STREAM_RDBUF)); in jas_stream_flushbuf()
826 len = stream->ptr_ - stream->bufstart_; in jas_stream_flushbuf()
828 n = (*stream->ops_->write_)(stream->obj_, (char *) in jas_stream_flushbuf()
829 stream->bufstart_, len); in jas_stream_flushbuf()
831 stream->flags_ |= JAS_STREAM_ERR; in jas_stream_flushbuf()
835 stream->cnt_ = stream->bufsize_; in jas_stream_flushbuf()
836 stream->ptr_ = stream->bufstart_; in jas_stream_flushbuf()
838 stream->bufmode_ |= JAS_STREAM_WRBUF; in jas_stream_flushbuf()
841 assert(stream->cnt_ > 0); in jas_stream_flushbuf()
842 return jas_stream_putc2(stream, c); in jas_stream_flushbuf()
905 long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt) in jas_stream_setrwcount() argument
909 old = stream->rwcnt_; in jas_stream_setrwcount()
910 stream->rwcnt_ = rwcnt; in jas_stream_setrwcount()
914 int jas_stream_display(jas_stream_t *stream, FILE *fp, int n) in jas_stream_display() argument
936 if ((c = jas_stream_getc(stream)) == EOF) { in jas_stream_display()
965 long jas_stream_length(jas_stream_t *stream) in jas_stream_length() argument
969 if ((oldpos = jas_stream_tell(stream)) < 0) { in jas_stream_length()
972 if (jas_stream_seek(stream, 0, SEEK_END) < 0) { in jas_stream_length()
975 if ((pos = jas_stream_tell(stream)) < 0) { in jas_stream_length()
978 if (jas_stream_seek(stream, oldpos, SEEK_SET) < 0) { in jas_stream_length()