|
#define | ws_strdup(src) wmem_strdup(NULL, src) |
|
#define | ws_strndup(src, len) wmem_strndup(NULL, src, len) |
|
#define | ws_strdup_printf(...) wmem_strdup_printf(NULL, __VA_ARGS__) |
|
#define | ws_strdup_vprintf(fmt, ap) wmem_strdup_vprintf(NULL, fmt, ap) |
|
|
WS_DLL_PUBLIC void * | wmem_memdup (wmem_allocator_t *allocator, const void *source, const size_t size) G_GNUC_ALLOC_SIZE(3) |
| Copies a block of memory.
|
|
WS_DLL_PUBLIC int | wmem_compare_int (const void *a, const void *b) |
| Generic GCompareFunc to compare two signed integers.
|
|
WS_DLL_PUBLIC int | wmem_compare_uint (const void *a, const void *b) |
| Generic GCompareFunc to compare two unsigned integers.
|
|
WS_DLL_PUBLIC char * | wmem_strdup (wmem_allocator_t *allocator, const char *src) G_GNUC_MALLOC |
| Duplicate a string using the specified memory allocator.
|
|
WS_DLL_PUBLIC char * | wmem_strndup (wmem_allocator_t *allocator, const char *src, const size_t len) G_GNUC_MALLOC |
| Duplicate a string up to a specified length using the given memory allocator.
|
|
WS_DLL_PUBLIC char * | wmem_strdup_printf (wmem_allocator_t *allocator, const char *fmt,...) G_GNUC_MALLOC G_GNUC_PRINTF(2 |
| Allocate and format a string using the specified memory allocator.
|
|
WS_DLL_PUBLIC char * | wmem_strdup_vprintf (wmem_allocator_t *allocator, const char *fmt, va_list ap) G_GNUC_MALLOC |
| Allocate and format a string using a va_list and the specified memory allocator.
|
|
WS_DLL_PUBLIC const uint8_t * | ws_memmem (const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) |
| Return the first occurrence of needle in haystack.
|
|
A collection of misc. utility functions for wmem.
A collection of utility function for operating on C strings with wmem.
◆ wmem_compare_int()
WS_DLL_PUBLIC int wmem_compare_int |
( |
const void * |
a, |
|
|
const void * |
b |
|
) |
| |
Generic GCompareFunc to compare two signed integers.
Casts both a
and b
to const gint*
and returns the result of their comparison. This function is suitable for use with sorting or searching routines that accept a GCompareFunc
.
- Parameters
-
a | Pointer to the first signed integer. |
b | Pointer to the second signed integer. |
- Returns
- Negative if *a < *b, zero if *a == *b, positive if *a > *b.
◆ wmem_compare_uint()
WS_DLL_PUBLIC int wmem_compare_uint |
( |
const void * |
a, |
|
|
const void * |
b |
|
) |
| |
Generic GCompareFunc to compare two unsigned integers.
Casts both a
and b
to const guint*
and returns the result of their comparison. This function is suitable for use with sorting or searching routines that accept a GCompareFunc
.
- Parameters
-
a | Pointer to the first unsigned integer. |
b | Pointer to the second unsigned integer. |
- Returns
- Negative if *a < *b, zero if *a == *b, positive if *a > *b.
◆ wmem_memdup()
WS_DLL_PUBLIC void * wmem_memdup |
( |
wmem_allocator_t * |
allocator, |
|
|
const void * |
source, |
|
|
const size_t |
size |
|
) |
| |
Copies a block of memory.
- Parameters
-
allocator | The allocator object to use to allocate memory to copy into. |
source | The pointer to the memory block to copy. |
size | The amount of memory to copy. |
- Returns
- The location of the memory copy or NULL if size is 0.
◆ wmem_strdup()
WS_DLL_PUBLIC char * wmem_strdup |
( |
wmem_allocator_t * |
allocator, |
|
|
const char * |
src |
|
) |
| |
Duplicate a string using the specified memory allocator.
Allocates memory for a copy of the null-terminated string src
using the given allocator
, and returns a pointer to the newly allocated string.
- Parameters
-
allocator | Pointer to the memory allocator to use. |
src | Null-terminated string to duplicate. |
- Returns
- Pointer to the duplicated string, or NULL on failure.
- Note
- The returned memory is allocated and should be freed appropriately if not managed automatically.
◆ wmem_strdup_printf()
WS_DLL_PUBLIC char * wmem_strdup_printf |
( |
wmem_allocator_t * |
allocator, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Allocate and format a string using the specified memory allocator.
Formats a string using printf-style formatting and allocates memory for it using the given allocator. The resulting string is null-terminated.
- Parameters
-
allocator | Pointer to the memory allocator to use. |
fmt | Format string (as used in printf). |
... | Additional arguments to format into the string. |
- Returns
- Pointer to the newly allocated formatted string, or NULL on failure.
- Note
- The returned memory is allocated and should be freed appropriately if not managed automatically.
◆ wmem_strdup_vprintf()
WS_DLL_PUBLIC char * wmem_strdup_vprintf |
( |
wmem_allocator_t * |
allocator, |
|
|
const char * |
fmt, |
|
|
va_list |
ap |
|
) |
| |
Allocate and format a string using a va_list and the specified memory allocator.
Formats a string using a printf-style format string and a va_list of arguments, allocating memory for the resulting string using the given allocator.
- Parameters
-
allocator | Pointer to the memory allocator to use. |
fmt | Format string (as used in printf). |
ap | va_list containing the arguments to format into the string. |
- Returns
- Pointer to the newly allocated formatted string, or NULL on failure.
- Note
- The returned memory is allocated and should be freed appropriately if not managed automatically.
◆ wmem_strndup()
WS_DLL_PUBLIC char * wmem_strndup |
( |
wmem_allocator_t * |
allocator, |
|
|
const char * |
src, |
|
|
const size_t |
len |
|
) |
| |
Duplicate a string up to a specified length using the given memory allocator.
Allocates memory for a copy of the first len
characters of the null-terminated string src
using the specified allocator
. The resulting string is null-terminated.
- Parameters
-
allocator | Pointer to the memory allocator to use. |
src | Null-terminated source string to duplicate. |
len | Maximum number of characters to copy from the source string. |
- Returns
- Pointer to the newly allocated string, or NULL on failure.
- Note
- The returned memory is allocated and should be freed appropriately if not managed automatically.
◆ ws_memmem()
WS_DLL_PUBLIC const uint8_t * ws_memmem |
( |
const void * |
haystack, |
|
|
size_t |
haystack_len, |
|
|
const void * |
needle, |
|
|
size_t |
needle_len |
|
) |
| |
Return the first occurrence of needle in haystack.
- Parameters
-
haystack | The data to search |
haystack_len | The length of the search data |
needle | The string to look for |
needle_len | The length of the search string |
- Returns
- A pointer to the first occurrence of "needle" in "haystack". If "needle" isn't found or is NULL, NULL is returned. If "needle_len" is 0, a pointer to "haystack" is returned.