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 {
26  unsigned bufpos;
28  unsigned count;
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
int obuf_write_large(obuf *out, const char *data, unsigned datalen)
Definition: obuf_write.c:7
int obuf_pad(obuf *out, unsigned width, char ch)
Definition: obuf_pad.c:4
int obuf_putXll(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:52
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
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
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
int obuf_seek(obuf *out, unsigned offset)
Definition: obuf_seek.c:7
int obuf_sign_pad(obuf *out, int sign, unsigned width, char pad)
Definition: obuf_sign_pad.c:10
int obuf_putill(obuf *out, long long data)
Definition: obuf_putsllnumw.c:21
int obuf_putullnumw(obuf *out, unsigned long long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putullnumw.c:6
int obuf_putu(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:21
int obuf_putull(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:24
int obuf_open(obuf *out, const char *filename, int oflags, int mode, unsigned bufsize)
Definition: obuf_open.c:4
unsigned count
Definition: obuf.h:28
int obuf_init(obuf *out, int fd, obuf_fn fn, unsigned flags, unsigned bufsize)
Definition: obuf_init.c:5
int obuf_putxwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:31
int obuf_putf(obuf *out, const char *format,...)
Definition: obuf_putf.c:26
int obuf_putsnumw(obuf *out, long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putsnumw.c:5
int obuf_putsflush(obuf *out, const char *s)
Definition: obuf_putsflush.c:5
int(* obuf_fn)(int, const void *, unsigned long)
Definition: obuf.h:18
int obuf_putiwll(obuf *out, long long data, unsigned width, char pad)
Definition: obuf_putsllnumw.c:15
int obuf_putsllnumw(obuf *out, long long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putsllnumw.c:5
obuf_fn writefn
Definition: obuf.h:30
int obuf_put2s(obuf *out, const char *s1, const char *s2)
Definition: obuf_put2s.c:5
int obuf_putX(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:47
int obuf_putuw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:15
unsigned bufpos
Definition: obuf.h:26
iobuf io
Definition: obuf.h:24
int obuf_putfv(obuf *out, const char *format, va_list ap)
Definition: obuf_putf.c:6
int obuf_putuwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:18
int obuf_putc(obuf *out, char ch)
Definition: obuf_putc.c:4
int obuf_putXwll(obuf *out, unsigned long long data, unsigned width, char pad)
Definition: obuf_putullnumw.c:45
int obuf_putXw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:41
int obuf_putxw(obuf *out, unsigned long data, unsigned width, char pad)
Definition: obuf_putunumw.c:28
int obuf_puti(obuf *out, long data)
Definition: obuf_putsnumw.c:21
int obuf_putiw(obuf *out, long data, unsigned width, char pad)
Definition: obuf_putsnumw.c:15
Definition: obuf.h:21
obuf errbuf
Definition: obuf_stderr.c:7
int obuf_endl(obuf *out)
Definition: obuf_endl.c:4
Definition: iobuf_common.h:48
int obuf_close(obuf *out)
Definition: obuf_close.c:4
int obuf_flush(obuf *out)
Definition: obuf_flush.c:6
int obuf_putxll(obuf *out, unsigned long long data)
Definition: obuf_putullnumw.c:38
int obuf_sync(obuf *out)
Definition: obuf_sync.c:6
int obuf_write(obuf *out, const char *data, unsigned datalen)
Definition: obuf_write.c:30
int obuf_put3s(obuf *out, const char *s1, const char *s2, const char *s3)
Definition: obuf_put3s.c:5
obuf outbuf
Definition: obuf_stdout.c:7
int obuf_putns(obuf *out, unsigned int count,...)
Definition: obuf_putns.c:6
int obuf_putunumw(obuf *out, unsigned long num, unsigned width, char pad, unsigned base, const char *digits)
Definition: obuf_putunumw.c:5
int obuf_putx(obuf *out, unsigned long data)
Definition: obuf_putunumw.c:34
int obuf_putnetstring(obuf *out, const char *data, unsigned datalen)
Definition: obuf_putnetstring.c:4
int obuf_put4s(obuf *out, const char *s1, const char *s2, const char *s3, const char *s4)
Definition: obuf_put4s.c:5