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