77 #include <jasper/jas_config.h>
80 #if defined(JAS_HAVE_FCNTL_H)
108 #define JAS_STREAM_READ 0x0001
110 #define JAS_STREAM_WRITE 0x0002
112 #define JAS_STREAM_APPEND 0x0004
114 #define JAS_STREAM_BINARY 0x0008
116 #define JAS_STREAM_CREATE 0x0010
123 #define JAS_STREAM_UNBUF 0x0000
125 #define JAS_STREAM_LINEBUF 0x0001
127 #define JAS_STREAM_FULLBUF 0x0002
129 #define JAS_STREAM_BUFMODEMASK 0x000f
133 #define JAS_STREAM_FREEBUF 0x0008
135 #define JAS_STREAM_RDBUF 0x0010
137 #define JAS_STREAM_WRBUF 0x0020
144 #define JAS_STREAM_EOF 0x0001
146 #define JAS_STREAM_ERR 0x0002
148 #define JAS_STREAM_RWLIMIT 0x0004
150 #define JAS_STREAM_ERRMASK \
151 (JAS_STREAM_EOF | JAS_STREAM_ERR | JAS_STREAM_RWLIMIT)
158 #define JAS_STREAM_BUFSIZE 8192
160 #define JAS_STREAM_PERMS 0666
163 #define JAS_STREAM_MAXPUTBACK 16
173 typedef void jas_stream_obj_t;
182 ssize_t (*read_)(jas_stream_obj_t *obj,
char *buf,
size_t cnt);
185 ssize_t (*write_)(jas_stream_obj_t *obj,
const char *buf,
size_t cnt);
188 long (*seek_)(jas_stream_obj_t *obj,
long offset,
int origin);
191 int (*close_)(jas_stream_obj_t *obj);
222 jas_uchar *bufstart_;
235 jas_uchar tinybuf_[JAS_STREAM_MAXPUTBACK + 1];
238 const jas_stream_ops_t *ops_;
241 jas_stream_obj_t *obj_;
261 #if defined(JAS_WASI_LIBC)
262 #define L_tmpnam 4096
264 char pathname[L_tmpnam + 1];
265 } jas_stream_fileobj_t;
268 #define JAS_STREAM_FILEOBJ_DELONCLOSE 0x01
270 #define JAS_STREAM_FILEOBJ_NOCLOSE 0x02
296 } jas_stream_memobj_t;
452 #define jas_stream_eof(stream) \
453 (((stream)->flags_ & JAS_STREAM_EOF) != 0)
466 #define jas_stream_error(stream) \
467 (((stream)->flags_ & JAS_STREAM_ERR) != 0)
478 #define jas_stream_clearerr(stream) \
479 ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))
491 #define jas_stream_getrwlimit(stream) \
492 (((const jas_stream_t *)(stream))->rwlimit_)
521 #define jas_stream_getrwcount(stream) \
522 (((const jas_stream_t *)(stream))->rwcnt_)
557 #define jas_stream_getc(stream) jas_stream_getc_func(stream)
559 #define jas_stream_getc(stream) jas_stream_getc_macro(stream)
578 #define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
580 #define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
773 #define jas_stream_peekc(stream) \
774 (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
775 ((int)(*(stream)->ptr_)))
1048 JAS_EXPORT
int jas_stream_fillbuf(
jas_stream_t *stream,
int getflag);
1049 JAS_EXPORT
int jas_stream_flushbuf(
jas_stream_t *stream,
int c);
1050 JAS_EXPORT
int jas_stream_getc_func(
jas_stream_t *stream);
1051 JAS_EXPORT
int jas_stream_putc_func(
jas_stream_t *stream,
int c);
1054 static inline int jas_stream_getc2(
jas_stream_t *stream)
1056 if (--stream->cnt_ < 0)
1057 return jas_stream_fillbuf(stream, 1);
1060 return (
int)(*stream->ptr_++);
1063 static inline int jas_stream_getc_macro(
jas_stream_t *stream)
1065 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1068 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1069 stream->flags_ |= JAS_STREAM_RWLIMIT;
1073 return jas_stream_getc2(stream);
1077 static inline int jas_stream_putc2(
jas_stream_t *stream, jas_uchar c)
1079 stream->bufmode_ |= JAS_STREAM_WRBUF;
1081 if (--stream->cnt_ < 0)
1082 return jas_stream_flushbuf(stream, c);
1085 return (
int)(*stream->ptr_++ = c);
1089 static inline int jas_stream_putc_macro(
jas_stream_t *stream, jas_uchar c)
1091 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1094 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1095 stream->flags_ |= JAS_STREAM_RWLIMIT;
1099 return jas_stream_putc2(stream, c);
JAS_EXPORT jas_stream_t * jas_stream_fdopen(int fd, const char *mode)
Open a file descriptor as a stream.
Definition: jas_stream.c:523
JAS_EXPORT char * jas_stream_gets(jas_stream_t *stream, char *buffer, int buffer_size)
Read a line of input from a stream.
Definition: jas_stream.c:796
JAS_EXPORT int jas_stream_display(jas_stream_t *stream, FILE *fp, int count)
Print a hex dump of data read from a stream.
Definition: jas_stream.c:1148
JAS_EXPORT long jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit)
Set the read/write limit for a stream.
Definition: jas_stream.c:1138
JAS_EXPORT unsigned jas_stream_peek(jas_stream_t *stream, void *buffer, size_t count)
Attempt to retrieve one or more pending characters of input from a stream into a buffer without actua...
Definition: jas_stream.c:706
JAS_EXPORT jas_stream_t * jas_stream_tmpfile(void)
Open a temporary file as a stream.
Definition: jas_stream.c:473
JAS_EXPORT long jas_stream_tell(jas_stream_t *stream)
Get the current position within the stream.
Definition: jas_stream.c:901
JAS_EXPORT jas_stream_t * jas_stream_fopen(const char *filename, const char *mode)
Open a file as a stream.
Definition: jas_stream.c:283
JAS_EXPORT ssize_t jas_stream_gobble(jas_stream_t *stream, size_t count)
Consume (i.e., discard) characters from stream.
Definition: jas_stream.c:819
JAS_EXPORT ssize_t jas_stream_pad(jas_stream_t *stream, size_t count, int value)
Write a fill character multiple times to a stream.
Definition: jas_stream.c:831
JAS_EXPORT int jas_stream_printf(jas_stream_t *stream, const char *format,...)
Write formatted output to a stream.
Definition: jas_stream.c:770
JAS_EXPORT int jas_stream_puts(jas_stream_t *stream, const char *s)
Write a string to a stream.
Definition: jas_stream.c:783
JAS_EXPORT jas_stream_t * jas_stream_memopen(char *buffer, size_t buffer_size)
Open a memory buffer as a stream.
Definition: jas_stream.c:203
JAS_EXPORT int jas_stream_ungetc(jas_stream_t *stream, int c)
Put a character back on a stream.
Definition: jas_stream.c:635
JAS_EXPORT int jas_stream_flush(jas_stream_t *stream)
Flush any pending output to a stream.
Definition: jas_stream.c:976
JAS_EXPORT long jas_stream_seek(jas_stream_t *stream, long offset, int origin)
Set the current position within the stream.
Definition: jas_stream.c:867
JAS_DEPRECATED JAS_EXPORT jas_stream_t * jas_stream_memopen2(char *buffer, size_t buffer_size)
Do not use.
Definition: jas_stream.c:277
JAS_EXPORT int jas_stream_close(jas_stream_t *stream)
Close a stream.
Definition: jas_stream.c:593
JAS_EXPORT size_t jas_stream_write(jas_stream_t *stream, const void *buffer, size_t count)
Write characters from a buffer to a stream.
Definition: jas_stream.c:722
JAS_EXPORT JAS_ATTRIBUTE_PURE int jas_stream_isseekable(jas_stream_t *stream)
Determine if stream supports seeking.
Definition: jas_stream.c:847
JAS_EXPORT int jas_stream_copy(jas_stream_t *destination, jas_stream_t *source, ssize_t count)
Copy data from one stream to another.
Definition: jas_stream.c:1103
JAS_EXPORT long jas_stream_length(jas_stream_t *stream)
Get the size of the file associated with the specified stream.
Definition: jas_stream.c:1198
JAS_EXPORT jas_stream_t * jas_stream_freopen(const char *path, const char *mode, FILE *fp)
Open a stdio (i.e., C standard library) stream as a stream.
Definition: jas_stream.c:350
JAS_EXPORT int jas_stream_rewind(jas_stream_t *stream)
Seek to the beginning of a stream.
Definition: jas_stream.c:861
JAS_EXPORT size_t jas_stream_read(jas_stream_t *stream, void *buffer, size_t count)
Read characters from a stream into a buffer.
Definition: jas_stream.c:652
JAS_EXPORT long jas_stream_setrwcount(jas_stream_t *stream, long rw_count)
Set the read/write count for a stream.
Definition: jas_stream.c:1128
I/O stream object.
Definition: jas_stream.h:206