Go to the documentation of this file.
77 #include <jasper/jas_config.h>
81 #if defined(JAS_HAVE_FCNTL_H)
105 #define JAS_PATH_MAX PATH_MAX
107 #define JAS_PATH_MAX 4096
115 #define JAS_STREAM_READ 0x0001
117 #define JAS_STREAM_WRITE 0x0002
119 #define JAS_STREAM_APPEND 0x0004
121 #define JAS_STREAM_BINARY 0x0008
123 #define JAS_STREAM_CREATE 0x0010
130 #define JAS_STREAM_UNBUF 0x0000
132 #define JAS_STREAM_LINEBUF 0x0001
134 #define JAS_STREAM_FULLBUF 0x0002
136 #define JAS_STREAM_BUFMODEMASK 0x000f
140 #define JAS_STREAM_FREEBUF 0x0008
142 #define JAS_STREAM_RDBUF 0x0010
144 #define JAS_STREAM_WRBUF 0x0020
151 #define JAS_STREAM_EOF 0x0001
153 #define JAS_STREAM_ERR 0x0002
155 #define JAS_STREAM_RWLIMIT 0x0004
157 #define JAS_STREAM_ERRMASK \
158 (JAS_STREAM_EOF | JAS_STREAM_ERR | JAS_STREAM_RWLIMIT)
165 #define JAS_STREAM_BUFSIZE 8192
167 #define JAS_STREAM_PERMS 0666
170 #define JAS_STREAM_MAXPUTBACK 16
180 typedef void jas_stream_obj_t;
189 int (*read_)(jas_stream_obj_t *obj,
char *buf,
unsigned cnt);
192 int (*write_)(jas_stream_obj_t *obj,
const char *buf,
unsigned cnt);
195 long (*seek_)(jas_stream_obj_t *obj,
long offset,
int origin);
198 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[JAS_PATH_MAX + 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;
454 #define jas_stream_eof(stream) \
455 (((stream)->flags_ & JAS_STREAM_EOF) != 0)
467 #define jas_stream_error(stream) \
468 (((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_)
520 #define jas_stream_getrwcount(stream) \
521 (((const jas_stream_t *)(stream))->rwcnt_)
547 #define jas_stream_getc(stream) jas_stream_getc_func(stream)
549 #define jas_stream_getc(stream) jas_stream_getc_macro(stream)
558 #define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
560 #define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
601 unsigned jas_stream_read(jas_stream_t *stream,
void *buffer,
unsigned count);
627 unsigned jas_stream_peek(jas_stream_t *stream,
void *buffer,
size_t count);
703 JAS_DLLEXPORT
int jas_stream_puts(jas_stream_t *stream,
const char *s);
747 #define jas_stream_peekc(stream) \
748 (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
749 ((int)(*(stream)->ptr_)))
796 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
833 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
890 JAS_DLLEXPORT
int jas_stream_copy(jas_stream_t *destination, jas_stream_t *source,
int count);
965 JAS_DLLEXPORT
int jas_stream_pad(jas_stream_t *stream,
int count,
int value);
984 JAS_ATTRIBUTE_PURE JAS_DLLEXPORT
997 JAS_DLLEXPORT
int jas_stream_fillbuf(jas_stream_t *stream,
int getflag);
998 JAS_DLLEXPORT
int jas_stream_flushbuf(jas_stream_t *stream,
int c);
999 JAS_DLLEXPORT
int jas_stream_getc_func(jas_stream_t *stream);
1000 JAS_DLLEXPORT
int jas_stream_putc_func(jas_stream_t *stream,
int c);
1003 static inline int jas_stream_getc2(jas_stream_t *stream)
1005 if (--stream->cnt_ < 0)
1006 return jas_stream_fillbuf(stream, 1);
1009 return (
int)(*stream->ptr_++);
1012 static inline int jas_stream_getc_macro(jas_stream_t *stream)
1014 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1017 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1018 stream->flags_ |= JAS_STREAM_RWLIMIT;
1022 return jas_stream_getc2(stream);
1026 static inline int jas_stream_putc2(jas_stream_t *stream, jas_uchar c)
1028 stream->bufmode_ |= JAS_STREAM_WRBUF;
1030 if (--stream->cnt_ < 0)
1031 return jas_stream_flushbuf(stream, c);
1034 return (
int)(*stream->ptr_++ = c);
1038 static inline int jas_stream_putc_macro(jas_stream_t *stream, jas_uchar c)
1040 if (stream->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | JAS_STREAM_RWLIMIT))
1043 if (stream->rwlimit_ >= 0 && stream->rwcnt_ >= stream->rwlimit_) {
1044 stream->flags_ |= JAS_STREAM_RWLIMIT;
1048 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:558
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:467
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:547
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