PipeWire 1.6.8

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#include <stdlib.h>
9#include <string.h>
10#include <sys/un.h>
11#ifndef _POSIX_C_SOURCE
12# include <sys/mount.h>
13#endif
14#include <errno.h>
15#include <sys/types.h>
16
17#include <spa/utils/cleanup.h>
18#include <spa/utils/defs.h>
19#include <spa/pod/pod.h>
20
21#ifdef __cplusplus
22 extern "C" {
23#endif
24
25#ifndef ENODATA
26#define ENODATA 9919
27#endif
28
33
38
40 typedef void (*pw_destroy_t) (void *object);
41
42 const char *
43 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
44
45 char **
46 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
47
48 int
49 pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
50
51 char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens);
52
53 int pw_strv_find(char **a, const char *b);
54
55 int pw_strv_find_common(char **a, char **b);
56
57 void
58 pw_free_strv(char **str);
59
60 char *
61 pw_strip(char *str, const char *whitespace);
62
63#if !defined(strndupa)
64# define strndupa(s, n) \
65 ({ \
66 const char *__old = (s); \
67 size_t __len = strnlen(__old, (n)); \
68 char *__new = (char *) __builtin_alloca(__len + 1); \
69 memcpy(__new, __old, __len); \
70 __new[__len] = '\0'; \
71 __new; \
72 })
73#endif
74
75#if !defined(strdupa)
76# define strdupa(s) \
77 ({ \
78 const char *__old = (s); \
79 size_t __len = strlen(__old) + 1; \
80 char *__new = (char *) alloca(__len); \
81 (char *) memcpy(__new, __old, __len); \
82 })
83#endif
84
85 SPA_WARN_UNUSED_RESULT
86ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
87
88 void pw_random(void *buf, size_t buflen);
89
90#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
91
92 void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
93
94#ifdef PW_ENABLE_DEPRECATED
95#define PW_DEPRECATED(v) (v)
96#else
97#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
98#endif /* PW_ENABLE_DEPRECATED */
99
103
104SPA_DEFINE_AUTO_CLEANUP(pw_strv, char **, {
105 spa_clear_ptr(*thing, pw_free_strv);
106})
107
108#ifdef __cplusplus
109} /* extern "C" */
110#endif
111
112#endif /* PIPEWIRE_UTILS_H */
defs.h
spa/utils/defs.h
pw_strv_find
int pw_strv_find(char **a, const char *b)
Find a string in a NULL terminated array of strings.
Definition utils.c:195
pw_destroy_t
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition utils.h:44
pw_getrandom
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition utils.c:308
pw_random
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition utils.c:335
pw_free_strv
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition utils.c:235
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:37
pw_reallocarray
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition utils.c:367
pw_strv_find_common
int pw_strv_find_common(char **a, char **b)
Check if two NULL terminated arrays of strings have a common string.
Definition utils.c:215
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:98
pw_strv_parse
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
pw_strip
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition utils.c:256
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:60
SPA_WARN_UNUSED_RESULT
#define SPA_WARN_UNUSED_RESULT
Definition defs.h:313
pod.h
spa/pod/pod.h
string.h
spa/utils/string.h