PipeWire: utils.h Source File

PipeWire 0.3.67

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#include <spa/utils/defs.h>
20#include <spa/pod/pod.h>
21
33typedef void (*pw_destroy_t) (void *object);
34
35const char *
36 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
37
38char **
39 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
40
41int
42 pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
43
44void
45 pw_free_strv(char **str);
46
47char *
48 pw_strip(char *str, const char *whitespace);
49
50#if !defined(strndupa)
51# define strndupa(s, n) \
52 ({ \
53 const char *__old = (s); \
54 size_t __len = strnlen(__old, (n)); \
55 char *__new = (char *) __builtin_alloca(__len + 1); \
56 memcpy(__new, __old, __len); \
57 __new[__len] = '\0'; \
58 __new; \
59 })
60#endif
61
62#if !defined(strdupa)
63# define strdupa(s) \
64 ({ \
65 const char *__old = (s); \
66 size_t __len = strlen(__old) + 1; \
67 char *__new = (char *) alloca(__len); \
68 (char *) memcpy(__new, __old, __len); \
69 })
70#endif
71
72 SPA_WARN_UNUSED_RESULT
73ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
74
75void pw_random(void *buf, size_t buflen);
76
77#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
78
79void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
80
81#ifdef PW_ENABLE_DEPRECATED
82#define PW_DEPRECATED(v) (v)
83#else
84#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
85#endif /* PW_ENABLE_DEPRECATED */
86
91#ifdef __cplusplus
92} /* extern "C" */
93#endif
94
95#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:37
pw_random
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition: utils.c:214
pw_free_strv
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition: utils.c:118
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:32
pw_reallocarray
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition: utils.c:246
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:92
pw_strip
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition: utils.c:139
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:187
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:55
SPA_WARN_UNUSED_RESULT
#define SPA_WARN_UNUSED_RESULT
Definition: defs.h:289
pod.h
spa/pod/pod.h
string.h
spa/utils/string.h