PipeWire: PipeWire Utility Functions

PipeWire 0.3.37

Macros | Typedefs | Functions
PipeWire Utility Functions

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

## Detailed Description

Various utility functions.

## Macro Definition Documentation

## ◆ strdupa

#define strdupa | ( |  | s | ) |

Value:
({ \
const char *__old = (s); \
size_t __len = strlen(__old) + 1; \
char *__new = (char *) alloca(__len); \
(char *) memcpy(__new, __old, __len); \
})

## ◆ strndupa

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

Value:
({ \
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; \
})
n
const char unsigned long int n
Definition: pipewire/src/pipewire/i18n.h:35

## Typedef Documentation

## ◆ pw_destroy_t

typedef void(* pw_destroy_t) (void *object)

a function to destroy an item

## Function Documentation

## ◆ pw_free_strv()

void pw_free_strv | ( | char ** | str | ) |

Free a NULL terminated array of strings.

Parameters

  str | a NULL terminated array of string

Free all the strings in the array and the array

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

  | str | a string to split
  | delimiter | delimiter characters to split on
  | max_tokens | the max number of tokens to split
  [out] | n_tokens | the number of tokens

Returns
  a NULL terminated array of strings that should be freed with pw_free_strv.

References n.

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

  | str | a string to split
  | delimiter | delimiter characters to split on
  [out] | len | the length of the current string
  [in,out] | state | a 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.

Referenced by pw_context_load_module().

## ◆ pw_strip()

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

Strip all whitespace before and after a string.

Parameters

  str | a string to strip
  whitespace | characters to strip

Returns
  the stripped part of str

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