Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Macros | Functions
String Utilities

Macros

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

Functions

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.
 

Detailed Description

A collection of misc. utility functions for wmem.

A collection of utility function for operating on C strings with wmem.

Function Documentation

◆ 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
aPointer to the first signed integer.
bPointer 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
aPointer to the first unsigned integer.
bPointer 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
allocatorThe allocator object to use to allocate memory to copy into.
sourceThe pointer to the memory block to copy.
sizeThe 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
allocatorPointer to the memory allocator to use.
srcNull-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
allocatorPointer to the memory allocator to use.
fmtFormat 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
allocatorPointer to the memory allocator to use.
fmtFormat string (as used in printf).
apva_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
allocatorPointer to the memory allocator to use.
srcNull-terminated source string to duplicate.
lenMaximum 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
haystackThe data to search
haystack_lenThe length of the search data
needleThe string to look for
needle_lenThe 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.