PipeWire  0.3.43
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 #include <sys/un.h>
34 #ifndef _POSIX_C_SOURCE
35 # include <sys/mount.h>
36 #endif
37 
38 #include <spa/utils/defs.h>
39 #include <spa/pod/pod.h>
40 
52 typedef void (*pw_destroy_t) (void *object);
53 
54 const char *
55 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
56 
57 char **
58 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
59 
60 void
61 pw_free_strv(char **str);
62 
63 char *
64 pw_strip(char *str, const char *whitespace);
65 
66 #if !defined(strndupa)
67 # define strndupa(s, n) \
68  ({ \
69  const char *__old = (s); \
70  size_t __len = strnlen(__old, (n)); \
71  char *__new = (char *) __builtin_alloca(__len + 1); \
72  memcpy(__new, __old, __len); \
73  __new[__len] = '\0'; \
74  __new; \
75  })
76 #endif
77 
78 #if !defined(strdupa)
79 # define strdupa(s) \
80  ({ \
81  const char *__old = (s); \
82  size_t __len = strlen(__old) + 1; \
83  char *__new = (char *) alloca(__len); \
84  (char *) memcpy(__new, __old, __len); \
85  })
86 #endif
87 
88 ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
93 #ifdef __cplusplus
94 } /* extern "C" */
95 #endif
96 
97 #endif /* PIPEWIRE_UTILS_H */
spa/utils/defs.h
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition: utils.h:56
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition: utils.c:154
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition: utils.c:127
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition: utils.c:106
const 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:51
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:74
spa/pod/pod.h
spa/utils/string.h