PipeWire: utils.h Source File

PipeWire 0.3.66

Loading...
Searching...
No Matches
src/pipewire/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
29extern "C" {
30#endif
31
32#include <stdlib.h>
33#include <string.h>
34#include <sys/un.h>
35#ifndef _POSIX_C_SOURCE
36# include <sys/mount.h>
37#endif
38
39#include <spa/utils/defs.h>
40#include <spa/pod/pod.h>
41
53typedef void (*pw_destroy_t) (void *object);
54
55const char *
56 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
57
58char **
59 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
60
61int
62 pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
63
64void
65 pw_free_strv(char **str);
66
67char *
68 pw_strip(char *str, const char *whitespace);
69
70#if !defined(strndupa)
71# define strndupa(s, n) \
72 ({ \
73 const char *__old = (s); \
74 size_t __len = strnlen(__old, (n)); \
75 char *__new = (char *) __builtin_alloca(__len + 1); \
76 memcpy(__new, __old, __len); \
77 __new[__len] = '\0'; \
78 __new; \
79 })
80#endif
81
82#if !defined(strdupa)
83# define strdupa(s) \
84 ({ \
85 const char *__old = (s); \
86 size_t __len = strlen(__old) + 1; \
87 char *__new = (char *) alloca(__len); \
88 (char *) memcpy(__new, __old, __len); \
89 })
90#endif
91
92 SPA_WARN_UNUSED_RESULT
93ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
94
95void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
96
97#ifdef PW_ENABLE_DEPRECATED
98#define PW_DEPRECATED(v) (v)
99#else
100#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
101#endif /* PW_ENABLE_DEPRECATED */
102
107#ifdef __cplusplus
108} /* extern "C" */
109#endif
110
111#endif /* PIPEWIRE_UTILS_H */
defs.h
spa/utils/defs.h
pw_destroy_t
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition: src/pipewire/utils.h:57
pw_free_strv
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition: utils.c:137
pw_split_walk
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
pw_reallocarray
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition: utils.c:207
pw_split_ip
int pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[])
Split a string in-place based on delimiters.
Definition: utils.c:111
pw_strip
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition: utils.c:158
pw_getrandom
SPA_WARN_UNUSED_RESULT ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition: utils.c:185
pw_split_strv
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_WARN_UNUSED_RESULT
#define SPA_WARN_UNUSED_RESULT
Definition: defs.h:305
pod.h
spa/pod/pod.h
string.h
spa/utils/string.h