5#ifndef PIPEWIRE_UTILS_H
6#define PIPEWIRE_UTILS_H
15#ifndef _POSIX_C_SOURCE
16# include <sys/mount.h>
24#include <spa/utils/cleanup.h>
42pw_split_walk(
const char *str,
const char *delimiter,
size_t *len,
const char **state);
45pw_split_strv(
const char *str,
const char *delimiter,
int max_tokens,
int *n_tokens);
48pw_split_ip(
char *str,
const char *delimiter,
int max_tokens,
char *tokens[]);
50char **
pw_strv_parse(
const char *val,
size_t len,
int max_tokens,
int *n_tokens);
60pw_strip(
char *str,
const char *whitespace);
63# define strndupa(s, n) \
65 const char *__old = (s); \
66 size_t __len = strnlen(__old, (n)); \
67 char *__new = (char *) __builtin_alloca(__len + 1); \
68 memcpy(__new, __old, __len); \
69 __new[__len] = '\0'; \
77 const char *__old = (s); \
78 size_t __len = strlen(__old) + 1; \
79 char *__new = (char *) alloca(__len); \
80 (char *) memcpy(__new, __old, __len); \
85ssize_t
pw_getrandom(
void *buf,
size_t buflen,
unsigned int flags);
89#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
93#ifdef PW_ENABLE_DEPRECATED
94#define PW_DEPRECATED(v) (v)
96#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
103SPA_DEFINE_AUTO_CLEANUP(pw_strv,
char **, {
int pw_strv_find(char **a, const char *b)
Find a string in a NULL terminated array of strings.
Definition utils.c:196
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition utils.h:43
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition utils.c:309
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition utils.c:336
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition utils.c:236
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:37
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition utils.c:368
int pw_strv_find_common(char **a, char **b)
Check if two NULL terminated arrays of strings have a common string.
Definition utils.c:216
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:98
char ** pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens)
Parse an array of strings.
Definition utils.c:131
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition utils.c:257
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:60
#define SPA_WARN_UNUSED_RESULT
Definition defs.h:311