PipeWire  0.3.45
Utilities

Various utility functions. More...

Macros

#define strndupa(s, n)
 
#define strdupa(s)
 

Typedefs

typedef void(* pw_destroy_t) (void *object)
 a function to destroy an item More...
 

Functions

const char * pw_split_walk (const char *str, const char *delimiter, size_t *len, const char **state)
 Split a string based on delimiters. More...
 
char ** pw_split_strv (const char *str, const char *delimiter, int max_tokens, int *n_tokens)
 Split a string based on delimiters. More...
 
void pw_free_strv (char **str)
 Free a NULL terminated array of strings. More...
 
char * pw_strip (char *str, const char *whitespace)
 Strip all whitespace before and after a string. More...
 
ssize_t pw_getrandom (void *buf, size_t buflen, unsigned int flags)
 Fill a buffer with random data. More...
 

Detailed Description

Various utility functions.

Macro Definition Documentation

◆ strndupa

#define strndupa (   s,
 
)

◆ strdupa

#define strdupa (   s)

Typedef Documentation

◆ pw_destroy_t

typedef void(* pw_destroy_t) (void *object)

a function to destroy an item

Function Documentation

◆ 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.

Parameters
stra string to split
delimiterdelimiter characters to split on
[out]lenthe length of the current string
[in,out]statea state variable
Returns
a string or NULL when the end is reached

Repeatedly call this function to split str into all substrings delimited by delimiter. state should be set to NULL on the first invocation and passed to the function until NULL is returned.

◆ 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.

Parameters
stra string to split
delimiterdelimiter characters to split on
max_tokensthe max number of tokens to split
[out]n_tokensthe number of tokens
Returns
a NULL terminated array of strings that should be freed with pw_free_strv.

◆ pw_free_strv()

void pw_free_strv ( char **  str)

Free a NULL terminated array of strings.

Parameters
stra NULL terminated array of string

Free all the strings in the array and the array

◆ pw_strip()

char* pw_strip ( char *  str,
const char *  whitespace 
)

Strip all whitespace before and after a string.

Parameters
stra string to strip
whitespacecharacters to strip
Returns
the stripped part of str

Strip whitespace before and after str. str will be modified.

◆ pw_getrandom()

ssize_t pw_getrandom ( void *  buf,
size_t  buflen,
unsigned int  flags 
)

Fill a buffer with random data.

Parameters
bufa buffer to fill
buflenthe number of bytes to fill
flagsoptional flags
Returns
the number of bytes filled

Fill buf with buflen random bytes.