📄 jas_stream.h
字号:
/* The stream status. */ int flags_; /* The start of the buffer area to use for reading/writing. */ uchar *bufbase_; /* The start of the buffer area excluding the extra initial space for character putback. */ uchar *bufstart_; /* The buffer size. */ int bufsize_; /* The current position in the buffer. */ uchar *ptr_; /* The number of characters that must be read/written before the buffer needs to be filled/flushed. */ int cnt_; /* A trivial buffer to be used for unbuffered operation. */ uchar tinybuf_[JAS_STREAM_MAXPUTBACK + 1]; /* The operations for the underlying stream file object. */ jas_stream_ops_t *ops_; /* The underlying stream file object. */ jas_stream_obj_t *obj_; /* The number of characters read/written. */ long rwcnt_; /* The maximum number of characters that may be read/written. */ long rwlimit_;} jas_stream_t;/* * Regular file object. *//* Note: This is simply a file descriptor. */typedef int jas_stream_fileobj_t;/* * Memory file object. */typedef struct { /* The data associated with this file. */ uchar *buf_; /* The allocated size of the buffer for holding file data. */ int bufsize_; /* The length of the file. */ int_fast32_t len_; /* The seek position. */ int_fast32_t pos_; /* Is the buffer growable? */ int growable_; /* Was the buffer allocated internally? */ int myalloc_;} jas_stream_memobj_t;/******************************************************************************\* Macros/functions for opening and closing streams.\******************************************************************************//* Open a file as a stream. */jas_stream_t *jas_stream_fopen(const char *filename, const char *mode);/* Open a memory buffer as a stream. */jas_stream_t *jas_stream_memopen(char *buf, int bufsize);/* Open a file descriptor as a stream. */jas_stream_t *jas_stream_fdopen(int fd, const char *mode);/* Open a stdio stream as a stream. */jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp);/* Open a temporary file as a stream. */jas_stream_t *jas_stream_tmpfile();/* Close a stream. */int jas_stream_close(jas_stream_t *stream);/******************************************************************************\* Macros/functions for getting/setting the stream state.\******************************************************************************//* Get the EOF indicator for a stream. */#define jas_stream_eof(stream) \ (((stream)->flags_ & JAS_STREAM_EOF) != 0)/* Get the error indicator for a stream. */#define jas_stream_error(stream) \ (((stream)->flags_ & JAS_STREAM_ERR) != 0)/* Clear the error indicator for a stream. */#define jas_stream_clearerr(stream) \ ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))/* Get the read/write limit for a stream. */#define jas_stream_getrwlimit(stream) \ (((const jas_stream_t *)(stream))->rwlimit_)/* Set the read/write limit for a stream. */int jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit);/* Get the read/write count for a stream. */#define jas_stream_getrwcount(stream) \ (((const jas_stream_t *)(stream))->rwcnt_)/* Set the read/write count for a stream. */long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt);/******************************************************************************\* Macros/functions for I/O.\******************************************************************************//* Read a character from a stream. */#if defined(DEBUG)#define jas_stream_getc(stream) jas_stream_getc_func(stream)#else#define jas_stream_getc(stream) jas_stream_getc_macro(stream)#endif/* Write a character to a stream. */#if defined(DEBUG)#define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)#else#define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)#endif/* Read characters from a stream into a buffer. */int jas_stream_read(jas_stream_t *stream, void *buf, int cnt);/* Write characters from a buffer to a stream. */int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt);/* Write formatted output to a stream. */int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...);/* Write a string to a stream. */int jas_stream_puts(jas_stream_t *stream, const char *s);/* Read a line of input from a stream. */char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize);/* Look at the next character to be read from a stream without actually removing it from the stream. */#define jas_stream_peekc(stream) \ (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \ ((int)(*(stream)->ptr_)))/* Put a character back on a stream. */int jas_stream_ungetc(jas_stream_t *stream, int c);/******************************************************************************\* Macros/functions for getting/setting the stream position.\******************************************************************************//* Is it possible to seek on this stream? */int jas_stream_isseekable(jas_stream_t *stream);/* Set the current position within the stream. */long jas_stream_seek(jas_stream_t *stream, long offset, int origin);/* Get the current position within the stream. */long jas_stream_tell(jas_stream_t *stream);/* Seek to the beginning of a stream. */int jas_stream_rewind(jas_stream_t *stream);/******************************************************************************\* Macros/functions for flushing.\******************************************************************************//* Flush any pending output to a stream. */int jas_stream_flush(jas_stream_t *stream);/******************************************************************************\* Miscellaneous macros/functions.\******************************************************************************//* Copy data from one stream to another. */int jas_stream_copy(jas_stream_t *dst, jas_stream_t *src, int n);/* Display stream contents (for debugging purposes). */int jas_stream_display(jas_stream_t *stream, FILE *fp, int n);/* Consume (i.e., discard) characters from stream. */int jas_stream_gobble(jas_stream_t *stream, int n);/* Get the size of the file associated with the specified stream. The specified stream must be seekable. */long jas_stream_length(jas_stream_t *stream);/******************************************************************************\* Internal functions.\******************************************************************************//* The following functions are for internal use only! If you call themdirectly, you will die a horrible, miserable, and painful death! *//* Read a character from a stream. */#define jas_stream_getc_macro(stream) \ ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \ JAS_STREAM_RWLIMIT))) ? \ (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \ (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \ jas_stream_getc2(stream)) : EOF)#define jas_stream_getc2(stream) \ ((--(stream)->cnt_ < 0) ? jas_stream_fillbuf(stream, 1) : \ (++(stream)->rwcnt_, (int)(*(stream)->ptr_++)))/* Write a character to a stream. */#define jas_stream_putc_macro(stream, c) \ ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \ JAS_STREAM_RWLIMIT))) ? \ (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \ (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \ jas_stream_putc2(stream, c)) : EOF)#define jas_stream_putc2(stream, c) \ (((stream)->bufmode_ |= JAS_STREAM_WRBUF, --(stream)->cnt_ < 0) ? \ jas_stream_flushbuf((stream), (uchar)(c)) : \ (++(stream)->rwcnt_, (int)(*(stream)->ptr_++ = (c))))/* These prototypes need to be here for the sake of the stream_getc andstream_putc macros. */int jas_stream_fillbuf(jas_stream_t *stream, int getflag);int jas_stream_flushbuf(jas_stream_t *stream, int c);int jas_stream_getc_func(jas_stream_t *stream);int jas_stream_putc_func(jas_stream_t *stream, int c);#ifdef __cplusplus}#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -