1 #ifndef _VSTREAM_H_INCLUDED_
2 #define _VSTREAM_H_INCLUDED_
38 #define VSTREAM_JMP_BUF jmp_buf
40 #define VSTREAM_JMP_BUF sigjmp_buf
66 #define VSTREAM_IN (&vstream_fstd[0])
67 #define VSTREAM_OUT (&vstream_fstd[1])
68 #define VSTREAM_ERR (&vstream_fstd[2])
70 #define VSTREAM_FLAG_RD_ERR VBUF_FLAG_RD_ERR
71 #define VSTREAM_FLAG_WR_ERR VBUF_FLAG_WR_ERR
72 #define VSTREAM_FLAG_RD_TIMEOUT VBUF_FLAG_RD_TIMEOUT
73 #define VSTREAM_FLAG_WR_TIMEOUT VBUF_FLAG_WR_TIMEOUT
75 #define VSTREAM_FLAG_ERR VBUF_FLAG_ERR
76 #define VSTREAM_FLAG_EOF VBUF_FLAG_EOF
77 #define VSTREAM_FLAG_TIMEOUT VBUF_FLAG_TIMEOUT
78 #define VSTREAM_FLAG_FIXED VBUF_FLAG_FIXED
79 #define VSTREAM_FLAG_BAD VBUF_FLAG_BAD
81 #define VSTREAM_FLAG_READ (1<<8)
82 #define VSTREAM_FLAG_WRITE (1<<9)
83 #define VSTREAM_FLAG_SEEK (1<<10)
84 #define VSTREAM_FLAG_NSEEK (1<<11)
85 #define VSTREAM_FLAG_DOUBLE (1<<12)
86 #define VSTREAM_FLAG_DEADLINE (1<<13)
88 #define VSTREAM_PURGE_READ (1<<0)
89 #define VSTREAM_PURGE_WRITE (1<<1)
90 #define VSTREAM_PURGE_BOTH (VSTREAM_PURGE_READ|VSTREAM_PURGE_WRITE)
92 #define VSTREAM_BUFSIZE 4096
104 #define vstream_fread(v, b, n) vbuf_read(&(v)->buf, (b), (n))
105 #define vstream_fwrite(v, b, n) vbuf_write(&(v)->buf, (b), (n))
107 #define VSTREAM_PUTC(ch, vp) VBUF_PUT(&(vp)->buf, (ch))
108 #define VSTREAM_GETC(vp) VBUF_GET(&(vp)->buf)
109 #define vstream_ungetc(vp, ch) vbuf_unget(&(vp)->buf, (ch))
110 #define VSTREAM_EOF VBUF_EOF
112 #define VSTREAM_PUTCHAR(ch) VSTREAM_PUTC((ch), VSTREAM_OUT)
113 #define VSTREAM_GETCHAR() VSTREAM_GETC(VSTREAM_IN)
115 #define vstream_fileno(vp) ((vp)->fd)
116 #define vstream_req_bufsize(vp) ((const ssize_t) ((vp)->req_bufsize))
117 #define vstream_context(vp) ((vp)->context)
118 #define vstream_rd_error(vp) vbuf_rd_error(&(vp)->buf)
119 #define vstream_wr_error(vp) vbuf_wr_error(&(vp)->buf)
120 #define vstream_ferror(vp) vbuf_error(&(vp)->buf)
121 #define vstream_feof(vp) vbuf_eof(&(vp)->buf)
122 #define vstream_rd_timeout(vp) vbuf_rd_timeout(&(vp)->buf)
123 #define vstream_wr_timeout(vp) vbuf_wr_timeout(&(vp)->buf)
124 #define vstream_ftimeout(vp) vbuf_timeout(&(vp)->buf)
125 #define vstream_clearerr(vp) vbuf_clearerr(&(vp)->buf)
126 #define VSTREAM_PATH(vp) ((vp)->path ? (const char *) (vp)->path : "unknown_stream")
127 #define vstream_ftime(vp) ((time_t) ((vp)->iotime.tv_sec))
128 #define vstream_ftimeval(vp) ((vp)->iotime)
130 #define vstream_fstat(vp, fl) ((vp)->buf.flags & (fl))
135 #define VSTREAM_CTL_END 0
136 #define VSTREAM_CTL_READ_FN 1
137 #define VSTREAM_CTL_WRITE_FN 2
138 #define VSTREAM_CTL_PATH 3
139 #define VSTREAM_CTL_DOUBLE 4
140 #define VSTREAM_CTL_READ_FD 5
141 #define VSTREAM_CTL_WRITE_FD 6
142 #define VSTREAM_CTL_WAITPID_FN 7
143 #define VSTREAM_CTL_TIMEOUT 8
144 #define VSTREAM_CTL_EXCEPT 9
145 #define VSTREAM_CTL_CONTEXT 10
147 #define VSTREAM_CTL_DUPFD 11
149 #define VSTREAM_CTL_BUFSIZE 12
150 #define VSTREAM_CTL_SWAP_FD 13
151 #define VSTREAM_CTL_START_DEADLINE 14
152 #define VSTREAM_CTL_STOP_DEADLINE 15
155 #define CA_VSTREAM_CTL_END VSTREAM_CTL_END
156 #define CA_VSTREAM_CTL_READ_FN(v) VSTREAM_CTL_READ_FN, CHECK_VAL(VSTREAM_CTL, VSTREAM_RW_FN, (v))
157 #define CA_VSTREAM_CTL_WRITE_FN(v) VSTREAM_CTL_WRITE_FN, CHECK_VAL(VSTREAM_CTL, VSTREAM_RW_FN, (v))
158 #define CA_VSTREAM_CTL_PATH(v) VSTREAM_CTL_PATH, CHECK_CPTR(VSTREAM_CTL, char, (v))
159 #define CA_VSTREAM_CTL_DOUBLE VSTREAM_CTL_DOUBLE
160 #define CA_VSTREAM_CTL_READ_FD(v) VSTREAM_CTL_READ_FD, CHECK_VAL(VSTREAM_CTL, int, (v))
161 #define CA_VSTREAM_CTL_WRITE_FD(v) VSTREAM_CTL_WRITE_FD, CHECK_VAL(VSTREAM_CTL, int, (v))
162 #define CA_VSTREAM_CTL_WAITPID_FN(v) VSTREAM_CTL_WAITPID_FN, CHECK_VAL(VSTREAM_CTL, VSTREAM_WAITPID_FN, (v))
163 #define CA_VSTREAM_CTL_TIMEOUT(v) VSTREAM_CTL_TIMEOUT, CHECK_VAL(VSTREAM_CTL, int, (v))
164 #define CA_VSTREAM_CTL_EXCEPT VSTREAM_CTL_EXCEPT
165 #define CA_VSTREAM_CTL_CONTEXT(v) VSTREAM_CTL_CONTEXT, CHECK_PTR(VSTREAM_CTL, void, (v))
167 #define CA_VSTREAM_CTL_DUPFD(v) VSTREAM_CTL_DUPFD, CHECK_VAL(VSTREAM_CTL, int, (v))
169 #define CA_VSTREAM_CTL_BUFSIZE(v) VSTREAM_CTL_BUFSIZE, CHECK_VAL(VSTREAM_CTL, ssize_t, (v))
170 #define CA_VSTREAM_CTL_SWAP_FD(v) VSTREAM_CTL_SWAP_FD, CHECK_PTR(VSTREAM_CTL, VSTREAM, (v))
171 #define CA_VSTREAM_CTL_START_DEADLINE VSTREAM_CTL_START_DEADLINE
172 #define CA_VSTREAM_CTL_STOP_DEADLINE VSTREAM_CTL_STOP_DEADLINE
188 #define vstream_ispipe(vp) ((vp)->pid != 0)
191 #define VSTREAM_POPEN_END 0
192 #define VSTREAM_POPEN_COMMAND 1
193 #define VSTREAM_POPEN_ARGV 2
194 #define VSTREAM_POPEN_UID 3
195 #define VSTREAM_POPEN_GID 4
196 #define VSTREAM_POPEN_ENV 5
197 #define VSTREAM_POPEN_SHELL 6
198 #define VSTREAM_POPEN_WAITPID_FN 7
199 #define VSTREAM_POPEN_EXPORT 8
202 #define CA_VSTREAM_POPEN_END VSTREAM_POPEN_END
203 #define CA_VSTREAM_POPEN_COMMAND(v) VSTREAM_POPEN_COMMAND, CHECK_CPTR(VSTREAM_PPN, char, (v))
204 #define CA_VSTREAM_POPEN_ARGV(v) VSTREAM_POPEN_ARGV, CHECK_PPTR(VSTREAM_PPN, char, (v))
205 #define CA_VSTREAM_POPEN_UID(v) VSTREAM_POPEN_UID, CHECK_VAL(VSTREAM_PPN, uid_t, (v))
206 #define CA_VSTREAM_POPEN_GID(v) VSTREAM_POPEN_GID, CHECK_VAL(VSTREAM_PPN, gid_t, (v))
207 #define CA_VSTREAM_POPEN_ENV(v) VSTREAM_POPEN_ENV, CHECK_PPTR(VSTREAM_PPN, char, (v))
208 #define CA_VSTREAM_POPEN_SHELL(v) VSTREAM_POPEN_SHELL, CHECK_CPTR(VSTREAM_PPN, char, (v))
209 #define CA_VSTREAM_POPEN_WAITPID_FN(v) VSTREAM_POPEN_WAITPID_FN, CHECK_VAL(VSTREAM_PPN, VSTREAM_WAITPID_FN, (v))
210 #define CA_VSTREAM_POPEN_EXPORT(v) VSTREAM_POPEN_EXPORT, CHECK_PPTR(VSTREAM_PPN, char, (v))
224 #define VSTREAM_BST_FLAG_IN (1<<0)
225 #define VSTREAM_BST_FLAG_OUT (1<<1)
226 #define VSTREAM_BST_FLAG_PEND (1<<2)
228 #define VSTREAM_BST_MASK_DIR (VSTREAM_BST_FLAG_IN | VSTREAM_BST_FLAG_OUT)
229 #define VSTREAM_BST_IN_PEND (VSTREAM_BST_FLAG_IN | VSTREAM_BST_FLAG_PEND)
230 #define VSTREAM_BST_OUT_PEND (VSTREAM_BST_FLAG_OUT | VSTREAM_BST_FLAG_PEND)
232 #define vstream_peek(vp) vstream_bufstat((vp), VSTREAM_BST_IN_PEND)
245 #define vstream_setjmp(stream) setjmp((stream)->jbuf[0])
246 #define vstream_longjmp(stream, val) longjmp((stream)->jbuf[0], (val))
248 #define vstream_setjmp(stream) sigsetjmp((stream)->jbuf[0], 1)
249 #define vstream_longjmp(stream, val) siglongjmp((stream)->jbuf[0], (val))
258 #define vstream_flags(stream) ((const int) (stream)->buf.flags)
struct timeval time_limit
CHECK_PPTR_HELPER_DCL(VSTREAM_PPN, char)
VSTREAM * PRINTFLIKE(1, 2) vstream_printf(const char *
int vstream_fputs(const char *, VSTREAM *)
int vstream_pclose(VSTREAM *)
const char * vstream_peek_data(VSTREAM *)
VSTREAM * vstream_fprintf(VSTREAM *stream, const char *fmt,...)
#define WARN_UNUSED_RESULT
VSTREAM * vstream_vprintf(const char *, va_list)
VSTREAM * vstream_printf(const char *fmt,...)
int vstream_fpurge(VSTREAM *, int)
int vstream_fflush(VSTREAM *)
ssize_t(* VSTREAM_RW_FN)(int, void *, size_t, int, void *)
VSTREAM * vstream_vfprintf(VSTREAM *, const char *, va_list)
CHECK_VAL_HELPER_DCL(VSTREAM_CTL, ssize_t)
int vstream_fclose(VSTREAM *)
VSTREAM * vstream_fopen(const char *, int, mode_t)
VSTREAM * vstream_fdopen(int, int)
ssize_t vstream_bufstat(VSTREAM *, int)
int vstream_tweak_tcp(VSTREAM *)
int vstream_tweak_sock(VSTREAM *)
VSTREAM_WAITPID_FN waitpid_fn
off_t WARN_UNUSED_RESULT vstream_fseek(VSTREAM *, off_t, int)
pid_t(* VSTREAM_WAITPID_FN)(pid_t, WAIT_STATUS_T *, int)
VSTREAM VSTREAM const char VSTREAM * vstream_popen(int,...)
void vstream_control(VSTREAM *, int,...)
off_t vstream_ftell(VSTREAM *)
int vstream_fdclose(VSTREAM *)
CHECK_CPTR_HELPER_DCL(VSTREAM_CTL, char)
CHECK_PTR_HELPER_DCL(VSTREAM_CTL, void)