PipeWire 0.3.77
Loading...
Searching...
No Matches
src/pipewire/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
19#ifndef ENODATA
20#define ENODATA 9919
21#endif
22
23#include <spa/utils/defs.h>
24#include <spa/pod/pod.h>
25
37typedef void (*pw_destroy_t) (void *object);
38
39const char *
40pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
42char **
43pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
44
45int
46pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
47
48void
49pw_free_strv(char **str);
50
51char *
52pw_strip(char *str, const char *whitespace);
53
54#if !defined(strndupa)
55# define strndupa(s, n) \
56 ({ \
57 const char *__old = (s); \
58 size_t __len = strnlen(__old, (n)); \
59 char *__new = (char *) __builtin_alloca(__len + 1); \
60 memcpy(__new, __old, __len); \
61 __new[__len] = '\0'; \
62 __new; \
63 })
64#endif
65
66#if !defined(strdupa)
67# define strdupa(s) \
68 ({ \
69 const char *__old = (s); \
70 size_t __len = strlen(__old) + 1; \
71 char *__new = (char *) alloca(__len); \
72 (char *) memcpy(__new, __old, __len); \
73 })
74#endif
75
77ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
78
79void pw_random(void *buf, size_t buflen);
80
81#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
82
83void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
84
85#ifdef PW_ENABLE_DEPRECATED
86#define PW_DEPRECATED(v) (v)
87#else
88#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
89#endif /* PW_ENABLE_DEPRECATED */
90
95#ifdef __cplusplus
96} /* extern "C" */
97#endif
98
99#endif /* PIPEWIRE_UTILS_H */
spa/utils/defs.h
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition: src/pipewire/utils.h:41
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition: utils.c:219
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition: utils.c:119
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:33
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition: utils.c:251
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:93
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition: utils.c:140
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:192
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:56
#define SPA_WARN_UNUSED_RESULT
Definition: defs.h:289
spa/pod/pod.h
spa/utils/string.h