PipeWire: pipewire/utils.h Source File

PipeWire 1.2.6

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/cleanup.h>
25#include <spa/utils/defs.h>
26#include <spa/pod/pod.h>
27
39typedef void (*pw_destroy_t) (void *object);
40
41const char *
42 pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
43
44char **
45 pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
46
47int
48 pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
49
50char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens);
51
52int pw_strv_find(char **a, const char *b);
53
54int pw_strv_find_common(char **a, char **b);
55
56void
57 pw_free_strv(char **str);
58
59char *
60 pw_strip(char *str, const char *whitespace);
61
62#if !defined(strndupa)
63# define strndupa(s, n) \
64 ({ \
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'; \
70 __new; \
71 })
72#endif
73
74#if !defined(strdupa)
75# define strdupa(s) \
76 ({ \
77 const char *__old = (s); \
78 size_t __len = strlen(__old) + 1; \
79 char *__new = (char *) alloca(__len); \
80 (char *) memcpy(__new, __old, __len); \
81 })
82#endif
83
84 SPA_WARN_UNUSED_RESULT
85ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
86
87void pw_random(void *buf, size_t buflen);
88
89#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
90
91void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
92
93#ifdef PW_ENABLE_DEPRECATED
94#define PW_DEPRECATED(v) (v)
95#else
96#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
97#endif /* PW_ENABLE_DEPRECATED */
98
103SPA_DEFINE_AUTO_CLEANUP(pw_strv, char **, {
104 spa_clear_ptr(*thing, pw_free_strv);
105})
106
107#ifdef __cplusplus
108} /* extern "C" */
109#endif
110
111#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:196
pw_destroy_t
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition utils.h:43
pw_getrandom
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition utils.c:309
pw_random
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition utils.c:336
pw_free_strv
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition utils.c:236
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:368
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:216
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:257
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:311
pod.h
spa/pod/pod.h
string.h
spa/utils/string.h