Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Related Pages

iobuf.h

00001 #ifndef IO_BUF__H__ 00002 #define IO_BUF__H__ 00003 00004 #define LF ((char)10) 00005 #define CR ((char)13) 00006 #define CRLF "\015\012" 00007 00008 struct str; 00009 00023 #define IOBUF_EOF 1 00024 00025 #define IOBUF_ERROR 2 00026 00027 #define IOBUF_TIMEOUT 4 00028 00029 #define IOBUF_BADFLAGS 0xf 00030 00031 #define IOBUF_SEEKABLE 0x10 00032 00033 #define IOBUF_NEEDSCLOSE 0x20 00034 00035 #define IOBUF_NEEDSFREE 0x40 00036 00037 #define IOBUF_NEEDSMUNMAP 0x80 00038 extern unsigned iobuf_bufsize; 00039 00040 /* @} */ 00041 00046 struct iobuf 00047 { 00049 int fd; 00051 char* buffer; 00053 unsigned bufsize; 00055 unsigned buflen; 00057 unsigned bufstart; 00059 unsigned offset; 00061 unsigned timeout; 00063 unsigned flags; 00065 int errnum; 00066 }; 00067 typedef struct iobuf iobuf; 00068 00070 #define IOBUF_SET_ERROR(io) \ 00071 do{ \ 00072 io->flags |= IOBUF_ERROR; \ 00073 io->errnum = errno; \ 00074 return 0; \ 00075 }while(0) 00076 00077 int iobuf_init(iobuf* io, int fd, unsigned bufsize, char* buffer, 00078 unsigned flags); 00079 int iobuf_close(iobuf* io); 00081 #define iobuf_closed(io) ((io)->fd == -1) 00082 00083 #define iobuf_error(io) ((io)->flags & IOBUF_ERROR) 00084 00085 #define iobuf_timedout(io) ((io)->flags & IOBUF_TIMEOUT) 00086 00087 #define iobuf_bad(io) ((io)->flags & IOBUF_BADFLAGS) 00088 int iobuf_timeout(iobuf* io, int poll_out); 00089 /* @} */ 00090 00095 typedef int (*ibuf_fn)(int, void*, unsigned long); 00096 00098 struct ibuf 00099 { 00101 iobuf io; 00103 unsigned count; 00105 ibuf_fn readfn; 00106 }; 00107 typedef struct ibuf ibuf; 00108 00109 extern ibuf inbuf; 00110 00111 int ibuf_init(ibuf* in, int fd, ibuf_fn fn, unsigned flags, unsigned bufsize); 00112 int ibuf_open(ibuf* in, const char* filename, unsigned bufsize); 00113 int ibuf_eof(ibuf* in); 00115 #define ibuf_close(in) iobuf_close(&((in)->io)) 00116 00117 #define ibuf_closed(in) iobuf_closed(&((in)->io)) 00118 00119 #define ibuf_error(in) iobuf_error(&((in)->io)) 00120 00121 #define ibuf_timedout(in) iobuf_timedout(&((in)->io)) 00122 int ibuf_refill(ibuf* in); 00123 int ibuf_read_large(ibuf* in, char* data, unsigned datalen); 00124 int ibuf_read(ibuf* in, char* data, unsigned datalen); 00125 unsigned ibuf_tell(ibuf* in); 00126 int ibuf_seek(ibuf* in, unsigned offset); 00128 #define ibuf_rewind(in) ibuf_seek(in,0) 00129 00130 #define ibuf_seekfwd(in,off) ibuf_seek(ibuf_tell(in)+(offset)) 00131 00132 int ibuf_peek(ibuf* in, char* ch); 00133 int ibuf_getc(ibuf* in, char* ch); 00134 int ibuf_getu(ibuf* in, unsigned long* data); 00135 int ibuf_gets(ibuf* in, char* data, unsigned datalen, char boundary); 00136 int ibuf_getstr(ibuf* in, struct str* s, char boundary); 00137 int ibuf_getstr_crlf(ibuf* in, struct str* s); 00138 int ibuf_getnetstring(ibuf* in, struct str* s); 00139 int ibuf_readall(ibuf* in, struct str* s); 00140 int ibuf_openreadclose(const char* filename, struct str* s); 00141 /* @} */ 00142 00147 typedef int (*obuf_fn)(int, const void*, unsigned long); 00148 00150 struct obuf 00151 { 00153 iobuf io; 00155 unsigned bufpos; 00157 unsigned count; 00159 obuf_fn writefn; 00160 }; 00161 typedef struct obuf obuf; 00162 00163 extern obuf outbuf; 00164 extern obuf errbuf; 00165 00166 extern const char obuf_dec_digits[10]; 00167 extern const char obuf_hex_lcase_digits[16]; 00168 extern const char obuf_hex_ucase_digits[16]; 00169 00170 #include <fcntl.h> 00172 #define OBUF_CREATE O_CREAT 00173 00174 #define OBUF_EXCLUSIVE O_EXCL 00175 00176 #define OBUF_TRUNCATE O_TRUNC 00177 00178 #define OBUF_APPEND O_APPEND 00179 00180 int obuf_init(obuf* out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize); 00181 int obuf_open(obuf* out, const char* filename, int oflags, int mode, unsigned bufsize); 00182 int obuf_close(obuf* out); 00184 #define obuf_error(out) iobuf_error(&(out)->io) 00185 00186 #define obuf_closed(out) iobuf_closed(&(out)->io) 00187 00188 #define obuf_timedout(out) iobuf_timedout(&((out)->io)) 00189 int obuf_flush(obuf* out); 00190 int obuf_sync(obuf* out); 00191 int obuf_write_large(obuf* out, const char* data, unsigned datalen); 00192 int obuf_write(obuf* out, const char* data, unsigned datalen); 00193 int obuf_seek(obuf* out, unsigned offset); 00195 #define obuf_rewind(out) obuf_seek(out,0) 00196 00197 #define obuf_tell(out) ((out)->io.offset+(out)->bufpos) 00198 00199 int obuf_pad(obuf* out, unsigned width, char ch); 00200 int obuf_endl(obuf* out); 00201 int obuf_putc(obuf* out, char ch); 00203 #define obuf_puts(out,str) obuf_write(out,str,strlen(str)) 00204 int obuf_put2s(obuf* out, const char* s1, const char* s2); 00205 int obuf_put3s(obuf* out, const char* s1, const char* s2, const char* s3); 00206 int obuf_put4s(obuf* out, const char* s1, const char* s2, const char* s3, 00207 const char* s4); 00208 int obuf_put5s(obuf* out, const char* s1, const char* s2, const char* s3, 00209 const char* s4, const char* s5); 00210 int obuf_put6s(obuf* out, const char* s1, const char* s2, const char* s3, 00211 const char* s4, const char* s5, const char* s6); 00212 int obuf_put7s(obuf* out, const char* s1, const char* s2, const char* s3, 00213 const char* s4, const char* s5, const char* s6, const char* s7); 00214 int obuf_putns(obuf* out, unsigned int count, ...); 00216 #define obuf_putstr(out,str) obuf_write(out,(str)->s,(str)->len) 00217 int obuf_putsflush(obuf* out, const char* s); 00218 int obuf_puti(obuf* out, long data); 00219 int obuf_putiw(obuf* out, long data, unsigned width, char pad); 00220 int obuf_putu(obuf* out, unsigned long data); 00221 int obuf_putuw(obuf* out, unsigned long data, unsigned width, char pad); 00222 int obuf_putill(obuf* out, long long data); 00223 int obuf_putiwll(obuf* out, long long data, unsigned width, char pad); 00224 int obuf_putull(obuf* out, unsigned long long data); 00225 int obuf_putuwll(obuf* out, unsigned long long data, unsigned width, char pad); 00226 int obuf_putx(obuf* out, unsigned long data); 00227 int obuf_putxw(obuf* out, unsigned long data, unsigned width, char pad); 00228 int obuf_putX(obuf* out, unsigned long data); 00229 int obuf_putXw(obuf* out, unsigned long data, unsigned width, char pad); 00230 int obuf_putxll(obuf* out, unsigned long long data); 00231 int obuf_putxwll(obuf* out, unsigned long long data, unsigned width, char pad); 00232 int obuf_putXll(obuf* out, unsigned long long data); 00233 int obuf_putXwll(obuf* out, unsigned long long data, unsigned width, char pad); 00234 int obuf_putsnumw(obuf* out, long num, unsigned width, char pad, 00235 unsigned base, const char* digits); 00236 int obuf_putunumw(obuf* out, unsigned long num, unsigned width, char pad, 00237 unsigned base, const char* digits); 00238 int obuf_putsllnumw(obuf* out, long long num, unsigned width, char pad, 00239 unsigned base, const char* digits); 00240 int obuf_putullnumw(obuf* out, unsigned long long num, unsigned width, char pad, 00241 unsigned base, const char* digits); 00242 int obuf_putnetstring(obuf* out, const char* data, unsigned datalen); 00243 int obuf_sign_pad(obuf* out, int sign, unsigned width, char pad); 00244 /* @} */ 00245 00248 int iobuf_copy(ibuf* in, obuf* out); 00249 int iobuf_copyflush(ibuf* in, obuf* out); 00250 int ibuf_copytofd(ibuf* in, int out); 00251 int obuf_copyfromfd(int in, obuf* out); 00252 00253 /* @} */ 00254 00255 #endif

Generated on Mon Oct 25 23:09:40 2004 for bglibs by doxygen 1.3.8