]>
code.delx.au - pulseaudio/blob - src/pulsecore/strlist.c
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
32 #include <pulsecore/strbuf.h>
33 #include <pulsecore/macro.h>
34 #include <pulsecore/core-util.h>
42 #define ITEM_TO_TEXT(c) ((char*) (c) + PA_ALIGN(sizeof(pa_strlist)))
44 pa_strlist
* pa_strlist_prepend(pa_strlist
*l
, const char *s
) {
50 n
= pa_xmalloc(PA_ALIGN(sizeof(pa_strlist
)) + size
+ 1);
51 memcpy(ITEM_TO_TEXT(n
), s
, size
+ 1);
57 char *pa_strlist_tostring(pa_strlist
*l
) {
62 for (; l
; l
= l
->next
) {
64 pa_strbuf_puts(b
, " ");
66 pa_strbuf_puts(b
, ITEM_TO_TEXT(l
));
69 return pa_strbuf_tostring_free(b
);
72 pa_strlist
* pa_strlist_remove(pa_strlist
*l
, const char *s
) {
73 pa_strlist
*ret
= l
, *prev
= NULL
;
79 if (!strcmp(ITEM_TO_TEXT(l
), s
)) {
80 pa_strlist
*n
= l
->next
;
101 void pa_strlist_free(pa_strlist
*l
) {
109 pa_strlist
* pa_strlist_pop(pa_strlist
*l
, char **s
) {
119 *s
= pa_xstrdup(ITEM_TO_TEXT(l
));
125 pa_strlist
* pa_strlist_parse(const char *s
) {
126 pa_strlist
*head
= NULL
, *p
= NULL
;
127 const char *state
= NULL
;
130 while ((r
= pa_split_spaces(s
, &state
))) {
132 size_t size
= strlen(r
);
134 n
= pa_xmalloc(PA_ALIGN(sizeof(pa_strlist
)) + size
+ 1);
136 memcpy(ITEM_TO_TEXT(n
), r
, size
+1);
150 pa_strlist
*pa_strlist_reverse(pa_strlist
*l
) {
151 pa_strlist
*r
= NULL
;