Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
/* PipeWire */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef PIPEWIRE_UTILS_H
#define PIPEWIRE_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/un.h>
#ifndef _POSIX_C_SOURCE
# include <sys/mount.h>
#endif
#include <errno.h>
#ifndef ENODATA
#define ENODATA 9919
#endif
#include <spa/utils/defs.h>
#include <spa/pod/pod.h>
typedef void (*pw_destroy_t) (void *object);
const char *
pw_split_walk(const char *str, const char *delimiter, size_t *len, const char **state);
char **
pw_split_strv(const char *str, const char *delimiter, int max_tokens, int *n_tokens);
int
pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]);
char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens);
int pw_strv_find(char **a, const char *b);
int pw_strv_find_common(char **a, char **b);
void
pw_free_strv(char **str);
char *
pw_strip(char *str, const char *whitespace);
#if !defined(strndupa)
# define strndupa(s, n) \
({ \
const char *__old = (s); \
size_t __len = strnlen(__old, (n)); \
char *__new = (char *) __builtin_alloca(__len + 1); \
memcpy(__new, __old, __len); \
__new[__len] = '\0'; \
__new; \
})
#endif
#if !defined(strdupa)
# define strdupa(s) \
({ \
const char *__old = (s); \
size_t __len = strlen(__old) + 1; \
char *__new = (char *) alloca(__len); \
(char *) memcpy(__new, __old, __len); \
})
#endif
SPA_WARN_UNUSED_RESULT
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
void pw_random(void *buf, size_t buflen);
#define pw_rand32() ({ uint32_t val; pw_random(&val, sizeof(val)); val; })
void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
#ifdef PW_ENABLE_DEPRECATED
#define PW_DEPRECATED(v) (v)
#else
#define PW_DEPRECATED(v) ({ __typeof__(v) _v SPA_DEPRECATED = (v); (void)_v; (v); })
#endif /* PW_ENABLE_DEPRECATED */
#ifdef __cplusplus
} /* extern "C" */
#endif
#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:166
pw_destroy_t
void(* pw_destroy_t)(void *object)
a function to destroy an item
Definition utils.h:42
pw_getrandom
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
Fill a buffer with random data.
Definition utils.c:279
pw_random
void pw_random(void *buf, size_t buflen)
Fill a buffer with random data.
Definition utils.c:306
pw_free_strv
void pw_free_strv(char **str)
Free a NULL terminated array of strings.
Definition utils.c:206
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:36
pw_reallocarray
void * pw_reallocarray(void *ptr, size_t nmemb, size_t size)
Definition utils.c:338
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:186
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:97
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:130
pw_strip
char * pw_strip(char *str, const char *whitespace)
Strip all whitespace before and after a string.
Definition utils.c:227
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:59
SPA_WARN_UNUSED_RESULT
#define SPA_WARN_UNUSED_RESULT
Definition defs.h:293
pod.h
spa/pod/pod.h
string.h
spa/utils/string.h