PipeWire  0.3.15
utils.h
Go to the documentation of this file.
1 /* PipeWire
2  *
3  * Copyright © 2018 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef PIPEWIRE_UTILS_H
26 #define PIPEWIRE_UTILS_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <string.h>
33 
34 #include <spa/utils/defs.h>
35 #include <spa/pod/pod.h>
36 
43 typedef void (*pw_destroy_t) (void *object);
44 
45 const char *
46 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
47 
48 char **
49 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
50 
51 void
52 pw_free_strv(char **str);
53 
54 char *
55 pw_strip(char *str, const char *whitespace);
56 
57 #if !defined(strndupa)
58 # define strndupa(s, n) \
59  ({ \
60  const char *__old = (s); \
61  size_t __len = strnlen(__old, (n)); \
62  char *__new = (char *) __builtin_alloca(__len + 1); \
63  memcpy(__new, __old, __len); \
64  __new[__len] = '\0'; \
65  __new; \
66  })
67 #endif
68 
69 #ifdef __cplusplus
70 } /* extern "C" */
71 #endif
72 
73 #endif /* PIPEWIRE_UTILS_H */
pw_utils::pw_split_walk
const SPA_EXPORT char * pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state)
Split a string based on delimiters.
Definition: utils.c:45
pw_utils::pw_split_strv
SPA_EXPORT char ** pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens)
Split a string based on delimiters.
Definition: utils.c:71
array.h
pw_array
An array object.
Definition: array.h:43
utils.h
pw_array::pw_array_add_ptr
#define pw_array_add_ptr(a, p)
Add a pointer to array.
Definition: array.h:158
log.h
pw_utils::pw_strip
SPA_EXPORT char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition: utils.c:124
pw_utils::pw_destroy_t
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition: utils.h:43
pw_array::data
void * data
pointer to array data
Definition: array.h:44
pw_utils::pw_free_strv
SPA_EXPORT void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition: utils.c:105
pw_array::pw_array_init
static void pw_array_init(struct pw_array *arr, size_t extend)
Initialize the array with given extend.
Definition: array.h:85