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);
JAS_DLLEXPORT int jas_stream_printf(jas_stream_t *stream, const char *format,...)
Write formatted output to a stream.
Definition: jas_stream.c:781
JAS_DLLEXPORT unsigned jas_stream_read(jas_stream_t *stream, void *buffer, unsigned count)
Read characters from a stream into a buffer.
Definition: jas_stream.c:670
JAS_DLLEXPORT int jas_stream_ungetc(jas_stream_t *stream, int c)
Put a character back on a stream.
Definition: jas_stream.c:652
JAS_ATTRIBUTE_PURE JAS_DLLEXPORT long jas_stream_length(jas_stream_t *stream)
Get the size of the file associated with the specified stream.
Definition: jas_stream.c:1225
JAS_DLLEXPORT int jas_stream_rewind(jas_stream_t *stream)
Seek to the beginning of a stream.
Definition: jas_stream.c:885
JAS_DLLEXPORT jas_stream_t * jas_stream_fdopen(int fd, const char *mode)
Open a file descriptor as a stream.
Definition: jas_stream.c:540
JAS_DLLEXPORT jas_stream_t * jas_stream_fopen(const char *filename, const char *mode)
Open a file as a stream.
Definition: jas_stream.c:301
JAS_DLLEXPORT 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:807
JAS_DLLEXPORT int jas_stream_gobble(jas_stream_t *stream, int count)
Consume (i.e., discard) characters from stream.
Definition: jas_stream.c:831
JAS_ATTRIBUTE_PURE JAS_DLLEXPORT int jas_stream_isseekable(jas_stream_t *stream)
Determine if stream supports seeking.
Definition: jas_stream.c:871
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
JAS_DLLEXPORT jas_stream_t * jas_stream_tmpfile(void)
Open a temporary file as a stream.
Definition: jas_stream.c:490
JAS_DLLEXPORT 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_DLLEXPORT long jas_stream_seek(jas_stream_t *stream, long offset, int origin)
Set the current position within the stream.
Definition: jas_stream.c:891
JAS_DLLEXPORT 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:720
JAS_DLLEXPORT int jas_stream_copy(jas_stream_t *destination, jas_stream_t *source, int count)
Copy data from one stream to another.
Definition: jas_stream.c:1129
JAS_DLLEXPORT int jas_stream_pad(jas_stream_t *stream, int count, int value)
Write a fill character multiple times to a stream.
Definition: jas_stream.c:850
JAS_DLLEXPORT long jas_stream_setrwcount(jas_stream_t *stream, long rw_count)
Set the read/write count for a stream.
Definition: jas_stream.c:1154
JAS_DLLEXPORT jas_stream_t * jas_stream_memopen2(char *buffer, size_t buffer_size)
Definition: jas_stream.c:189
JAS_DLLEXPORT int jas_stream_flush(jas_stream_t *stream)
Flush any pending output to a stream.
Definition: jas_stream.c:1001
JAS_DLLEXPORT int jas_stream_puts(jas_stream_t *stream, const char *s)
Write a string to a stream.
Definition: jas_stream.c:794
JAS_DLLEXPORT int jas_stream_close(jas_stream_t *stream)
Close a stream.
Definition: jas_stream.c:610
JAS_DLLEXPORT jas_stream_t * jas_stream_memopen(char *buffer, int buffer_size)
Open a memory buffer as a stream.
Definition: jas_stream.c:276
JAS_ATTRIBUTE_PURE JAS_DLLEXPORT long jas_stream_tell(jas_stream_t *stream)
Get the current position within the stream.
Definition: jas_stream.c:926
JAS_DLLEXPORT 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:1174
JAS_DLLEXPORT unsigned jas_stream_write(jas_stream_t *stream, const void *buffer, unsigned count)
Write characters from a buffer to a stream.
Definition: jas_stream.c:735