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 int (*read_)(jas_stream_obj_t *obj,
char *buf,
unsigned cnt);
185 int (*write_)(jas_stream_obj_t *obj,
const char *buf,
unsigned cnt);
188 long (*seek_)(jas_stream_obj_t *obj,
long offset,
int origin);
191 int (*close_)(jas_stream_obj_t *obj);
215 jas_uchar *bufstart_;
228 jas_uchar tinybuf_[JAS_STREAM_MAXPUTBACK + 1];
231 const jas_stream_ops_t *ops_;
234 jas_stream_obj_t *obj_;
254 char pathname[L_tmpnam + 1];
255 } jas_stream_fileobj_t;
258 #define JAS_STREAM_FILEOBJ_DELONCLOSE 0x01
260 #define JAS_STREAM_FILEOBJ_NOCLOSE 0x02
286 } jas_stream_memobj_t;
447 #define jas_stream_eof(stream) \
448 (((stream)->flags_ & JAS_STREAM_EOF) != 0)
460 #define jas_stream_error(stream) \
461 (((stream)->flags_ & JAS_STREAM_ERR) != 0)
471 #define jas_stream_clearerr(stream) \
472 ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))
484 #define jas_stream_getrwlimit(stream) \
485 (((const jas_stream_t *)(stream))->rwlimit_)
513 #define jas_stream_getrwcount(stream) \
514 (((const jas_stream_t *)(stream))->rwcnt_)
540 #define jas_stream_getc(stream) jas_stream_getc_func(stream)
542 #define jas_stream_getc(stream) jas_stream_getc_macro(stream)
551 #define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
553 #define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
594 unsigned jas_stream_read(jas_stream_t *stream,
void *buffer,
unsigned count);
620 unsigned jas_stream_peek(jas_stream_t *stream,
void *buffer,
size_t count);
696 JAS_DLLEXPORT
int jas_stream_puts(jas_stream_t *stream,
const char *s);
740 #define jas_stream_peekc(stream) \
741 (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
742 ((int)(*(stream)->ptr_)))
789 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
826 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
883 JAS_DLLEXPORT
int jas_stream_copy(jas_stream_t *destination, jas_stream_t *source,
int count);
958 JAS_DLLEXPORT
int jas_stream_pad(jas_stream_t *stream,
int count,
int value);
977 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
990 JAS_DLLEXPORT
int jas_stream_fillbuf(jas_stream_t *stream,
int getflag);
991 JAS_DLLEXPORT
int jas_stream_flushbuf(jas_stream_t *stream,
int c);
992 JAS_DLLEXPORT
int jas_stream_getc_func(jas_stream_t *stream);
993 JAS_DLLEXPORT
int jas_stream_putc_func(jas_stream_t *stream,
int c);
996 static inline int jas_stream_getc2(jas_stream_t *stream)
998 if (--stream->cnt_ < 0)
999 return jas_stream_fillbuf(stream, 1);
1002 return (
int)(*stream->ptr_++);
1005 static inline int jas_stream_getc_macro(jas_stream_t *stream)
1007 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1010 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1011 stream->flags_ |= JAS_STREAM_RWLIMIT;
1015 return jas_stream_getc2(stream);
1019 static inline int jas_stream_putc2(jas_stream_t *stream, jas_uchar c)
1021 stream->bufmode_ |= JAS_STREAM_WRBUF;
1023 if (--stream->cnt_ < 0)
1024 return jas_stream_flushbuf(stream, c);
1027 return (
int)(*stream->ptr_++ = c);
1031 static inline int jas_stream_putc_macro(jas_stream_t *stream, jas_uchar c)
1033 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1036 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1037 stream->flags_ |= JAS_STREAM_RWLIMIT;
1041 return jas_stream_putc2(stream, c);
int jas_stream_printf(jas_stream_t *stream, const char *fmt,...)
Write formatted output to a stream.
Definition: jas_stream.c:781
long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt)
Set the read/write count for a stream.
Definition: jas_stream.c:1154
#define jas_stream_putc(stream, c)
jas_stream_putc Write a character to a stream.
Definition: jas_stream.h:551
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:1174
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:368
jas_stream_t * jas_stream_fopen(const char *filename, const char *mode)
Open a file as a stream.
Definition: jas_stream.c:301
unsigned jas_stream_read(jas_stream_t *stream, void *buf, unsigned cnt)
Read characters from a stream into a buffer.
Definition: jas_stream.c:670
int jas_stream_close(jas_stream_t *stream)
Close a stream.
Definition: jas_stream.c:610
long jas_stream_tell(jas_stream_t *stream)
Get the current position within the stream.
Definition: jas_stream.c:926
int jas_stream_gobble(jas_stream_t *stream, int n)
Consume (i.e., discard) characters from stream.
Definition: jas_stream.c:831
jas_stream_t * jas_stream_fdopen(int fd, const char *mode)
Open a file descriptor as a stream.
Definition: jas_stream.c:540
int jas_stream_ungetc(jas_stream_t *stream, int c)
Put a character back on a stream.
Definition: jas_stream.c:652
#define jas_stream_error(stream)
Get the error indicator for a stream.
Definition: jas_stream.h:460
int jas_stream_rewind(jas_stream_t *stream)
Seek to the beginning of a stream.
Definition: jas_stream.c:885
jas_stream_t * jas_stream_memopen2(char *buf, size_t bufsize)
Definition: jas_stream.c:189
int jas_stream_isseekable(jas_stream_t *stream)
Determine if stream supports seeking.
Definition: jas_stream.c:871
jas_stream_t * jas_stream_memopen(char *buf, int bufsize)
Open a memory buffer as a stream.
Definition: jas_stream.c:276
#define jas_stream_getc(stream)
jas_stream_getc Read a character from a stream.
Definition: jas_stream.h:540
JasPer Debugging-Related Functionality.
char * jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize)
Read a line of input from a stream.
Definition: jas_stream.c:807
long jas_stream_seek(jas_stream_t *stream, long offset, int origin)
Set the current position within the stream.
Definition: jas_stream.c:891
int jas_stream_puts(jas_stream_t *stream, const char *s)
Write a string to a stream.
Definition: jas_stream.c:794
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:720
JAS_DLLEXPORT long jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit)
Set the read/write limit for a stream.
Definition: jas_stream.c:1164
unsigned jas_stream_write(jas_stream_t *stream, const void *buf, unsigned cnt)
Write characters from a buffer to a stream.
Definition: jas_stream.c:735
int jas_stream_copy(jas_stream_t *out, jas_stream_t *in, int n)
Copy data from one stream to another.
Definition: jas_stream.c:1129
int jas_stream_flush(jas_stream_t *stream)
Flush any pending output to a stream.
Definition: jas_stream.c:1001
long jas_stream_length(jas_stream_t *stream)
Get the size of the file associated with the specified stream.
Definition: jas_stream.c:1225
int jas_stream_pad(jas_stream_t *stream, int n, int c)
Write a fill character multiple times to a stream.
Definition: jas_stream.c:850
jas_stream_t * jas_stream_tmpfile()
Open a temporary file as a stream.
Definition: jas_stream.c:490