PipeWire 1.1.0
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* PipeWire */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef PIPEWIRE_UTILS_H
6#define PIPEWIRE_UTILS_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <stdlib.h>
13#include <string.h>
14#include <sys/un.h>
15#ifndef _POSIX_C_SOURCE
16# include <sys/mount.h>
17#endif
18#include <errno.h>
19
20#ifndef ENODATA
21#define ENODATA 9919
22#endif
23
24#include <spa/utils/defs.h>
25#include <spa/pod/pod.h>
26
38typedef void (*pw_destroy_t) (void *object);
39
40const char *
41pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
43char **
44pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
45
46int
47pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
48
49char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens);
50
51int pw_strv_find(char **a, const char *b);
52
53int pw_strv_find_common(char **a, char **b);
54
55void
56pw_free_strv(char **str);
57
58char *
59pw_strip(char *str, const char *whitespace);
60
61#if !defined(strndupa)
62# define strndupa(s, n) \
63 ({ \
64 const char *__old = (s); \
65 size_t __len = strnlen(__old, (n)); \
66 char *__new = (char *) __builtin_alloca(__len + 1); \
67 memcpy(__new, __old, __len); \
68 __new[__len] = '\0'; \
69 __new; \
70 })
71#endif
72
73#if !defined(strdupa)
74# define strdupa(s) \
75 ({ \
76 const char *__old = (s); \
77 size_t __len = strlen(__old) + 1; \
78 char *__new = (char *) alloca(__len); \
79 (char *) memcpy(__new, __old, __len); \
80 })
81#endif
82
84ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
85
86void pw_random(void *buf, size_t buflen);
87
88#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
89
90void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
91
92#ifdef PW_ENABLE_DEPRECATED
93#define PW_DEPRECATED(v) (v)
94#else
95#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
96#endif /* PW_ENABLE_DEPRECATED */
97
102#ifdef __cplusplus
103} /* extern "C" */
104#endif
105
106#endif /* PIPEWIRE_UTILS_H */
spa/utils/defs.h
int pw_strv_find(char **a, const char *b)
Find a string in a NULL terminated array of strings.
Definition utils.c:166
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition utils.h:42
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition utils.c:279
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition utils.c:306
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition utils.c:206
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:36
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition utils.c:338
int pw_strv_find_common(char **a, char **b)
Check if two NULL terminated arrays of strings have a common string.
Definition utils.c:186
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:97
char ** pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens)
Parse an array of strings.
Definition utils.c:130
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition utils.c:227
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:59
#define SPA_WARN_UNUSED_RESULT
Definition defs.h:301
spa/pod/pod.h
spa/utils/string.h