bglibs: obuf.h Source File

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Related Pages
- Examples

# obuf.h

    00001 /* $Id: obuf.h 616 2005-08-19 20:11:01Z bruce $ */
    00002 #ifndef IO_BUF__OBUF__H__
    00003 #define IO_BUF__OBUF__H__
    00004
    00005 #include <stdarg.h>
    00006 #include <iobuf/common.h>
    00007
    00018 typedef int (*obuf_fn)(int, const void*, unsigned long);
    00019
    00021 struct obuf
    00022 {
    00024   iobuf io;
    00026   unsigned bufpos;
    00028   unsigned count;
    00030   obuf_fn writefn;
    00031 };
    00033 typedef struct obuf obuf;
    00034
    00035 extern obuf outbuf;
    00036 extern obuf errbuf;
    00037
    00038 extern const char obuf_dec_digits[10];
    00039 extern const char obuf_hex_lcase_digits[16];
    00040 extern const char obuf_hex_ucase_digits[16];
    00041
    00043 #define OBUF_CREATE O_CREAT
    00044
    00045 #define OBUF_EXCLUSIVE O_EXCL
    00046
    00047 #define OBUF_TRUNCATE O_TRUNC
    00048
    00049 #define OBUF_APPEND O_APPEND
    00050
    00051 int obuf_init(obuf* out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize);
    00052 int obuf_open(obuf* out, const char* filename, int oflags, int mode, unsigned bufsize);
    00053 int obuf_close(obuf* out);
    00055 #define obuf_error(out) iobuf_error(&(out)->io)
    00056
    00057 #define obuf_closed(out) iobuf_closed(&(out)->io)
    00058
    00059 #define obuf_timedout(out) iobuf_timedout(&((out)->io))
    00060 int obuf_flush(obuf* out);
    00061 int obuf_sync(obuf* out);
    00062 int obuf_write_large(obuf* out, const char* data, unsigned datalen);
    00063 int obuf_write(obuf* out, const char* data, unsigned datalen);
    00064 int obuf_seek(obuf* out, unsigned offset);
    00066 #define obuf_rewind(out) obuf_seek(out,0)
    00067
    00068 #define obuf_tell(out) ((out)->io.offset+(out)->bufpos)
    00069
    00070 int obuf_pad(obuf* out, unsigned width, char ch);
    00071 int obuf_endl(obuf* out);
    00072 int obuf_putc(obuf* out, char ch);
    00074 #define obuf_puts(out,str) obuf_write(out,str,strlen(str))
    00075 int obuf_put2s(obuf* out, const char* s1, const char* s2);
    00076 int obuf_put3s(obuf* out, const char* s1, const char* s2, const char* s3);
    00077 int obuf_put4s(obuf* out, const char* s1, const char* s2, const char* s3,
    00078                const char* s4);
    00079 int obuf_put5s(obuf* out, const char* s1, const char* s2, const char* s3,
    00080                const char* s4, const char* s5);
    00081 int obuf_put6s(obuf* out, const char* s1, const char* s2, const char* s3,
    00082                const char* s4, const char* s5, const char* s6);
    00083 int obuf_put7s(obuf* out, const char* s1, const char* s2, const char* s3,
    00084                const char* s4, const char* s5, const char* s6, const char* s7);
    00085 int obuf_putns(obuf* out, unsigned int count, ...);
    00086 int obuf_putf(obuf* out, const char* format, ...);
    00087 int obuf_putfv(obuf* out, const char* format, va_list ap);
    00089 #define obuf_putstr(out,str) obuf_write(out,(str)->s,(str)->len)
    00090 int obuf_putsflush(obuf* out, const char* s);
    00091 int obuf_puti(obuf* out, long data);
    00092 int obuf_putiw(obuf* out, long data, unsigned width, char pad);
    00093 int obuf_putu(obuf* out, unsigned long data);
    00094 int obuf_putuw(obuf* out, unsigned long data, unsigned width, char pad);
    00095 int obuf_putill(obuf* out, long long data);
    00096 int obuf_putiwll(obuf* out, long long data, unsigned width, char pad);
    00097 int obuf_putull(obuf* out, unsigned long long data);
    00098 int obuf_putuwll(obuf* out, unsigned long long data, unsigned width, char pad);
    00099 int obuf_putx(obuf* out, unsigned long data);
    00100 int obuf_putxw(obuf* out, unsigned long data, unsigned width, char pad);
    00101 int obuf_putX(obuf* out, unsigned long data);
    00102 int obuf_putXw(obuf* out, unsigned long data, unsigned width, char pad);
    00103 int obuf_putxll(obuf* out, unsigned long long data);
    00104 int obuf_putxwll(obuf* out, unsigned long long data, unsigned width, char pad);
    00105 int obuf_putXll(obuf* out, unsigned long long data);
    00106 int obuf_putXwll(obuf* out, unsigned long long data, unsigned width, char pad);
    00107 int obuf_putsnumw(obuf* out, long num, unsigned width, char pad,
    00108                   unsigned base, const char* digits);
    00109 int obuf_putunumw(obuf* out, unsigned long num, unsigned width, char pad,
    00110                   unsigned base, const char* digits);
    00111 int obuf_putsllnumw(obuf* out, long long num, unsigned width, char pad,
    00112                     unsigned base, const char* digits);
    00113 int obuf_putullnumw(obuf* out, unsigned long long num, unsigned width, char pad,
    00114                     unsigned base, const char* digits);
    00115 int obuf_putnetstring(obuf* out, const char* data, unsigned datalen);
    00116 int obuf_sign_pad(obuf* out, int sign, unsigned width, char pad);
    00119 #endif