]>
code.delx.au - pulseaudio/blob - polyp/strbuf.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <sys/types.h>
36 #ifdef __STDC_VERSION__
37 #if __STDC_VERSION__ >= 199901L
56 struct chunk
*head
, *tail
;
59 struct pa_strbuf
*pa_strbuf_new(void) {
60 struct pa_strbuf
*sb
= pa_xmalloc(sizeof(struct pa_strbuf
));
62 sb
->head
= sb
->tail
= NULL
;
66 void pa_strbuf_free(struct pa_strbuf
*sb
) {
69 struct chunk
*c
= sb
->head
;
70 sb
->head
= sb
->head
->next
;
77 char *pa_strbuf_tostring(struct pa_strbuf
*sb
) {
82 t
= pa_xmalloc(sb
->length
+1);
85 for (c
= sb
->head
; c
; c
= c
->next
) {
86 memcpy(e
, c
->text
, c
->length
);
95 char *pa_strbuf_tostring_free(struct pa_strbuf
*sb
) {
98 t
= pa_strbuf_tostring(sb
);
103 void pa_strbuf_puts(struct pa_strbuf
*sb
, const char *t
) {
105 pa_strbuf_putsn(sb
, t
, strlen(t
));
108 void pa_strbuf_putsn(struct pa_strbuf
*sb
, const char *t
, size_t l
) {
115 c
= pa_xmalloc(sizeof(struct chunk
)+l
);
119 memcpy(c
->text
, t
, l
);
133 /* The following is based on an example from the GNU libc documentation */
135 int pa_strbuf_printf(struct pa_strbuf
*sb
, const char *format
, ...) {
137 struct chunk
*c
= NULL
;
144 c
= pa_xrealloc(c
, sizeof(struct chunk
)+size
);
146 va_start(ap
, format
);
147 r
= vsnprintf(c
->text
, size
, format
, ap
);
150 if (r
> -1 && r
< size
) {
168 if (r
> -1) /* glibc 2.1 */