bglibs: obuf.h Source File

bglibs

obuf.h
1 #ifndef IO_BUF__OBUF__H__
2 #define IO_BUF__OBUF__H__
3
4 #include <stdarg.h>
5 #include "sysdeps.h"
6 #include "iobuf_common.h"
7
18 typedef int (*obuf_fn)(int, const void*, unsigned long);
19
21 struct obuf
22 {
24 iobuf io;
26 unsigned bufpos;
28 unsigned count;
30 obuf_fn writefn;
31 };
33 typedef struct obuf obuf;
34
35 extern obuf outbuf;
36 extern obuf errbuf;
37
38 extern const char obuf_dec_digits[10] __DEPRECATED__;
39 extern const char obuf_hex_lcase_digits[16] __DEPRECATED__;
40 extern const char obuf_hex_ucase_digits[16] __DEPRECATED__;
41
43 #define OBUF_CREATE O_CREAT
44
45 #define OBUF_EXCLUSIVE O_EXCL
46
47 #define OBUF_TRUNCATE O_TRUNC
48
49 #define OBUF_APPEND O_APPEND
50
51 int obuf_init(obuf* out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize);
52 int obuf_open(obuf* out, const char* filename, int oflags, int mode, unsigned bufsize);
53 int obuf_close(obuf* out);
55 #define obuf_error(out) iobuf_error(&(out)->io)
56
57 #define obuf_closed(out) iobuf_closed(&(out)->io)
58
59 #define obuf_timedout(out) iobuf_timedout(&((out)->io))
60 int obuf_flush(obuf* out);
61 int obuf_sync(obuf* out);
62 int obuf_write_large(obuf* out, const char* data, unsigned datalen);
63 int obuf_write(obuf* out, const char* data, unsigned datalen);
64 int obuf_seek(obuf* out, unsigned offset);
66 #define obuf_rewind(out) obuf_seek(out,0)
67
68 #define obuf_tell(out) ((out)->io.offset+(out)->bufpos)
69
70 int obuf_pad(obuf* out, unsigned width, char ch);
71 int obuf_endl(obuf* out);
72 int obuf_putc(obuf* out, char ch);
74 #define obuf_puts(out,str) obuf_write(out,str,strlen(str))
75 int obuf_put2s(obuf* out, const char* s1, const char* s2);
76 int obuf_put3s(obuf* out, const char* s1, const char* s2, const char* s3);
77 int obuf_put4s(obuf* out, const char* s1, const char* s2, const char* s3,
78 const char* s4);
79 int obuf_put5s(obuf* out, const char* s1, const char* s2, const char* s3,
80 const char* s4, const char* s5);
81 int obuf_put6s(obuf* out, const char* s1, const char* s2, const char* s3,
82 const char* s4, const char* s5, const char* s6);
83 int obuf_put7s(obuf* out, const char* s1, const char* s2, const char* s3,
84 const char* s4, const char* s5, const char* s6, const char* s7);
85 int obuf_putns(obuf* out, unsigned int count, ...);
86 int obuf_putf(obuf* out, const char* format, ...);
87 int obuf_putfv(obuf* out, const char* format, va_list ap);
89 #define obuf_putstr(out,str) obuf_write(out,(str)->s,(str)->len)
90 int obuf_putsflush(obuf* out, const char* s);
91 int obuf_puti(obuf* out, long data);
92 int obuf_putiw(obuf* out, long data, unsigned width, char pad);
93 int obuf_putu(obuf* out, unsigned long data);
94 int obuf_putuw(obuf* out, unsigned long data, unsigned width, char pad);
95 int obuf_putill(obuf* out, long long data);
96 int obuf_putiwll(obuf* out, long long data, unsigned width, char pad);
97 int obuf_putull(obuf* out, unsigned long long data);
98 int obuf_putuwll(obuf* out, unsigned long long data, unsigned width, char pad);
99 int obuf_putx(obuf* out, unsigned long data);
100 int obuf_putxw(obuf* out, unsigned long data, unsigned width, char pad);
101 int obuf_putX(obuf* out, unsigned long data);
102 int obuf_putXw(obuf* out, unsigned long data, unsigned width, char pad);
103 int obuf_putxll(obuf* out, unsigned long long data);
104 int obuf_putxwll(obuf* out, unsigned long long data, unsigned width, char pad);
105 int obuf_putXll(obuf* out, unsigned long long data);
106 int obuf_putXwll(obuf* out, unsigned long long data, unsigned width, char pad);
107 int obuf_putsnumw(obuf* out, long num, unsigned width, char pad,
108 unsigned base, const char* digits);
109 int obuf_putunumw(obuf* out, unsigned long num, unsigned width, char pad,
110 unsigned base, const char* digits);
111 int obuf_putsllnumw(obuf* out, long long num, unsigned width, char pad,
112 unsigned base, const char* digits);
113 int obuf_putullnumw(obuf* out, unsigned long long num, unsigned width, char pad,
114 unsigned base, const char* digits);
115 int obuf_putnetstring(obuf* out, const char* data, unsigned datalen);
116 int obuf_sign_pad(obuf* out, int sign, unsigned width, char pad);
119 #endif
obuf_write_large
int obuf_write_large(obuf *out, const char *data, unsigned datalen)
Definition: obuf_write.c:7
obuf_pad
int obuf_pad(obuf *out, unsigned width, char ch)
Definition: obuf_pad.c:4
obuf_putXll
int obuf_putXll(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:52
obuf_put5s
int obuf_put5s(obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
Definition: obuf_put5s.c:5
obuf_put7s
int obuf_put7s(obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
Definition: obuf_put7s.c:5
obuf_put6s
int obuf_put6s(obuf *out, const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
Definition: obuf_put6s.c:5
obuf_seek
int obuf_seek(obuf *out, unsigned offset)
Definition: obuf_seek.c:7
obuf_sign_pad
int obuf_sign_pad(obuf *out, int sign, unsigned width, char pad)
Definition: obuf_sign_pad.c:10
obuf_putill
int obuf_putill(obuf *out, long long data)
Definition: obuf_putsllnumw.c:21
obuf_putullnumw
int obuf_putullnumw(obuf *out, unsigned long long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putullnumw.c:6
obuf_putu
int obuf_putu(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:21
obuf_putull
int obuf_putull(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:24
obuf_open
int obuf_open(obuf *out, const char *filename, int oflags, int mode, unsigned bufsize)
Definition: obuf_open.c:4
obuf::count
unsigned count
Definition: obuf.h:28
obuf_init
int obuf_init(obuf *out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize)
Definition: obuf_init.c:5
obuf_putxwll
int obuf_putxwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:31
obuf_putf
int obuf_putf(obuf *out, const char *format,...)
Definition: obuf_putf.c:26
obuf_putsnumw
int obuf_putsnumw(obuf *out, long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putsnumw.c:5
obuf_putsflush
int obuf_putsflush(obuf *out, const char *s)
Definition: obuf_putsflush.c:5
obuf_fn
int(* obuf_fn)(int, const void *, unsigned long)
Definition: obuf.h:18
obuf_putiwll
int obuf_putiwll(obuf *out, long long data, unsigned width, char pad)
Definition: obuf_putsllnumw.c:15
obuf_putsllnumw
int obuf_putsllnumw(obuf *out, long long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putsllnumw.c:5
obuf::writefn
obuf_fn writefn
Definition: obuf.h:30
obuf_put2s
int obuf_put2s(obuf *out, const char *s1, const char *s2)
Definition: obuf_put2s.c:5
obuf_putX
int obuf_putX(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:47
obuf_putuw
int obuf_putuw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:15
obuf::bufpos
unsigned bufpos
Definition: obuf.h:26
obuf::io
iobuf io
Definition: obuf.h:24
obuf_putfv
int obuf_putfv(obuf *out, const char *format, va_list ap)
Definition: obuf_putf.c:6
obuf_putuwll
int obuf_putuwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:18
obuf_putc
int obuf_putc(obuf *out, char ch)
Definition: obuf_putc.c:4
obuf_putXwll
int obuf_putXwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:45
obuf_putXw
int obuf_putXw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:41
obuf_putxw
int obuf_putxw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:28
obuf_puti
int obuf_puti(obuf *out, long data)
Definition: obuf_putsnumw.c:21
obuf_putiw
int obuf_putiw(obuf *out, long data, unsigned width, char pad)
Definition: obuf_putsnumw.c:15
obuf
Definition: obuf.h:21
errbuf
obuf errbuf
Definition: obuf_stderr.c:7
obuf_endl
int obuf_endl(obuf *out)
Definition: obuf_endl.c:4
iobuf
Definition: iobuf_common.h:48
obuf_close
int obuf_close(obuf *out)
Definition: obuf_close.c:4
obuf_flush
int obuf_flush(obuf *out)
Definition: obuf_flush.c:6
obuf_putxll
int obuf_putxll(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:38
obuf_sync
int obuf_sync(obuf *out)
Definition: obuf_sync.c:6
obuf_write
int obuf_write(obuf *out, const char *data, unsigned datalen)
Definition: obuf_write.c:30
obuf_put3s
int obuf_put3s(obuf *out, const char *s1, const char *s2, const char *s3)
Definition: obuf_put3s.c:5
outbuf
obuf outbuf
Definition: obuf_stdout.c:7
obuf_putns
int obuf_putns(obuf *out, unsigned int count,...)
Definition: obuf_putns.c:6
obuf_putunumw
int obuf_putunumw(obuf *out, unsigned long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putunumw.c:5
obuf_putx
int obuf_putx(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:34
obuf_putnetstring
int obuf_putnetstring(obuf *out, const char *data, unsigned datalen)
Definition: obuf_putnetstring.c:4
obuf_put4s
int obuf_put4s(obuf *out, const char *s1, const char *s2, const char *s3, const char *s4)
Definition: obuf_put4s.c:5