xref: /illumos-gate/usr/src/lib/lib9p/common/sbuf/sbuf.h (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * Redistribution and use in source and binary forms, with or without
3  * modification, are permitted providing that the following conditions
4  * are met:
5  * 1. Redistributions of source code must retain the above copyright
6  *    notice, this list of conditions and the following disclaimer.
7  * 2. Redistributions in binary form must reproduce the above copyright
8  *    notice, this list of conditions and the following disclaimer in the
9  *    documentation and/or other materials provided with the distribution.
10  *
11  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
14  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
15  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
16  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
17  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
20  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  * POSSIBILITY OF SUCH DAMAGE.
22  *
23  */
24 
25 /*
26  * Minimal libsbuf wrapper around libcustr for illumos.
27  */
28 
29 #ifndef LIB9P_SBUF_H
30 #define LIB9P_SBUF_H
31 
32 #include <stdarg.h>
33 #include <libcustr.h>
34 
35 struct sbuf
36 {
37 	custr_t *s_custr;
38 };
39 
40 struct sbuf *sbuf_new_auto(void);
41 char *sbuf_data(struct sbuf *s);
42 int sbuf_printf(struct sbuf *s, const char *fmt, ...);
43 void sbuf_delete(struct sbuf *s);
44 
45 #define	sbuf_cat(s, str) custr_append((s)->s_custr, (str))
46 #define	sbuf_vprintf(s, fmt, args) \
47     custr_append_vprintf((s)->s_custr, (fmt), (args))
48 #define	sbuf_data(s) custr_cstr((s)->s_custr)
49 #define	sbuf_finish(s)
50 
51 #endif /* LIB9P_SBUF_H */
52