Go to the documentation of this file.
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 char pathname[L_tmpnam + 1];
262 } jas_stream_fileobj_t;
265 #define JAS_STREAM_FILEOBJ_DELONCLOSE 0x01
267 #define JAS_STREAM_FILEOBJ_NOCLOSE 0x02
293 } jas_stream_memobj_t;
449 #define jas_stream_eof(stream) \
450 (((stream)->flags_ & JAS_STREAM_EOF) != 0)
463 #define jas_stream_error(stream) \
464 (((stream)->flags_ & JAS_STREAM_ERR) != 0)
475 #define jas_stream_clearerr(stream) \
476 ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))
488 #define jas_stream_getrwlimit(stream) \
489 (((const jas_stream_t *)(stream))->rwlimit_)
518 #define jas_stream_getrwcount(stream) \
519 (((const jas_stream_t *)(stream))->rwcnt_)
554 #define jas_stream_getc(stream) jas_stream_getc_func(stream)
556 #define jas_stream_getc(stream) jas_stream_getc_macro(stream)
575 #define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
577 #define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
770 #define jas_stream_peekc(stream) \
771 (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
772 ((int)(*(stream)->ptr_)))
1045 JAS_EXPORT
int jas_stream_fillbuf(
jas_stream_t *stream,
int getflag);
1046 JAS_EXPORT
int jas_stream_flushbuf(
jas_stream_t *stream,
int c);
1047 JAS_EXPORT
int jas_stream_getc_func(
jas_stream_t *stream);
1048 JAS_EXPORT
int jas_stream_putc_func(
jas_stream_t *stream,
int c);
1051 static inline int jas_stream_getc2(
jas_stream_t *stream)
1053 if (--stream->cnt_ < 0)
1054 return jas_stream_fillbuf(stream, 1);
1057 return (
int)(*stream->ptr_++);
1060 static inline int jas_stream_getc_macro(
jas_stream_t *stream)
1062 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1065 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1066 stream->flags_ |= JAS_STREAM_RWLIMIT;
1070 return jas_stream_getc2(stream);
1074 static inline int jas_stream_putc2(
jas_stream_t *stream, jas_uchar c)
1076 stream->bufmode_ |= JAS_STREAM_WRBUF;
1078 if (--stream->cnt_ < 0)
1079 return jas_stream_flushbuf(stream, c);
1082 return (
int)(*stream->ptr_++ = c);
1086 static inline int jas_stream_putc_macro(
jas_stream_t *stream, jas_uchar c)
1088 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1091 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1092 stream->flags_ |= JAS_STREAM_RWLIMIT;
1096 return jas_stream_putc2(stream, c);
#define jas_stream_error(stream)
Get the error indicator for a stream.
Definition: jas_stream.h:463
#define jas_stream_putc(stream, c)
jas_stream_putc Write a character to a stream.
Definition: jas_stream.h:575
jas_stream_t * jas_stream_fdopen(int fd, const char *mode)
Open a file descriptor as a stream.
Definition: jas_stream.c:521
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_logerrorf(const char *fmt,...)
Generate an error log message.
Definition: jas_debug.c:119
int jas_stream_copy(jas_stream_t *out, jas_stream_t *in, ssize_t n)
Copy data from one stream to another.
Definition: jas_stream.c:1101
void * jas_realloc2(void *ptr, size_t num_elements, size_t element_size)
Resize a block of allocated memory (with overflow checking).
Definition: jas_malloc.c:231
int jas_stream_ungetc(jas_stream_t *stream, int c)
Put a character back on a stream.
Definition: jas_stream.c:633
I/O stream object.
Definition: jas_stream.h:206
long jas_stream_tell(jas_stream_t *stream)
Get the current position within the stream.
Definition: jas_stream.c:899
long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt)
Set the read/write count for a stream.
Definition: jas_stream.c:1126
JAS_EXPORT long jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit)
Set the read/write limit for a stream.
Definition: jas_stream.c:1136
int jas_stream_printf(jas_stream_t *stream, const char *fmt,...)
Write formatted output to a stream.
Definition: jas_stream.c:768
ssize_t jas_stream_gobble(jas_stream_t *stream, size_t n)
Consume (i.e., discard) characters from stream.
Definition: jas_stream.c:817
jas_stream_t * jas_stream_memopen(char *buf, size_t bufsize)
Open a memory buffer as a stream.
Definition: jas_stream.c:203
int jas_stream_rewind(jas_stream_t *stream)
Seek to the beginning of a stream.
Definition: jas_stream.c:859
ssize_t jas_stream_pad(jas_stream_t *stream, size_t n, int c)
Write a fill character multiple times to a stream.
Definition: jas_stream.c:829
int jas_stream_display(jas_stream_t *stream, FILE *fp, int n)
Print a hex dump of data read from a stream.
Definition: jas_stream.c:1146
jas_stream_t * jas_stream_fopen(const char *filename, const char *mode)
Open a file as a stream.
Definition: jas_stream.c:283
size_t jas_stream_read(jas_stream_t *stream, void *buf, size_t cnt)
Read characters from a stream into a buffer.
Definition: jas_stream.c:650
JAS_EXPORT void * jas_malloc(size_t size)
Allocate memory.
Definition: jas_malloc.c:136
size_t jas_stream_write(jas_stream_t *stream, const void *buf, size_t cnt)
Write characters from a buffer to a stream.
Definition: jas_stream.c:720
unsigned jas_stream_peek(jas_stream_t *stream, void *buf, size_t cnt)
Attempt to retrieve one or more pending characters of input from a stream into a buffer without actua...
Definition: jas_stream.c:704
jas_stream_t * jas_stream_tmpfile()
Open a temporary file as a stream.
Definition: jas_stream.c:471
char * jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize)
Read a line of input from a stream.
Definition: jas_stream.c:794
long jas_stream_seek(jas_stream_t *stream, long offset, int origin)
Set the current position within the stream.
Definition: jas_stream.c:865
JasPer Debugging-Related Functionality.
int jas_stream_puts(jas_stream_t *stream, const char *s)
Write a string to a stream.
Definition: jas_stream.c:781
int jas_stream_close(jas_stream_t *stream)
Close a stream.
Definition: jas_stream.c:591
jas_stream_t * jas_stream_memopen2(char *buf, size_t bufsize)
Do not use.
Definition: jas_stream.c:277
JAS_EXPORT void jas_free(void *ptr)
Free memory.
Definition: jas_malloc.c:186
#define JAS_UNUSED(x)
Indicate that a variable may be unused (in order to avoid a compiler warning).
Definition: jas_compiler.h:145
#define jas_stream_getc(stream)
jas_stream_getc Read a character from a stream.
Definition: jas_stream.h:554
int jas_stream_flush(jas_stream_t *stream)
Flush any pending output to a stream.
Definition: jas_stream.c:974
long jas_stream_length(jas_stream_t *stream)
Get the size of the file associated with the specified stream.
Definition: jas_stream.c:1196
int jas_stream_isseekable(jas_stream_t *stream)
Determine if stream supports seeking.
Definition: jas_stream.c:845
JAS_EXPORT void jas_deprecated(const char *fmt,...)
Warn about the use of deprecated functionality.
Definition: jas_debug.c:266