summaryrefslogtreecommitdiffstats
path: root/wsutil/wmem/wmem_strutl.h
blob: 104a1ebadbc86271ee7cf600e5848fa99f727ecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** @file
 * Definitions for the Wireshark Memory Manager String Utilities
 * Copyright 2012, Evan Huus <eapache@gmail.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef __WMEM_STRUTL_H__
#define __WMEM_STRUTL_H__

#include <stdarg.h>

#include "wmem_core.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/** @addtogroup wmem
 *  @{
 *    @defgroup wmem-strutl String Utilities
 *
 *    A collection of utility function for operating on C strings with wmem.
 *
 *    @{
 */

WS_DLL_PUBLIC
char *
wmem_strdup(wmem_allocator_t *allocator, const char *src)
G_GNUC_MALLOC;

#define ws_strdup(src) wmem_strdup(NULL, src)

WS_DLL_PUBLIC
char *
wmem_strndup(wmem_allocator_t *allocator, const char *src, const size_t len)
G_GNUC_MALLOC;

#define ws_strndup(src, len) wmem_strndup(NULL, src, len)

WS_DLL_PUBLIC
char *
wmem_strdup_printf(wmem_allocator_t *allocator, const char *fmt, ...)
G_GNUC_MALLOC G_GNUC_PRINTF(2, 3);

#define ws_strdup_printf(...) wmem_strdup_printf(NULL, __VA_ARGS__)

WS_DLL_PUBLIC
char *
wmem_strdup_vprintf(wmem_allocator_t *allocator, const char *fmt, va_list ap)
G_GNUC_MALLOC;

#define ws_strdup_vprintf(fmt, ap) wmem_strdup_vprintf(NULL, fmt, ap)

/**
 * Return the first occurrence of needle in haystack.
 *
 * @param haystack The data to search
 * @param haystack_len The length of the search data
 * @param needle The string to look for
 * @param needle_len The length of the search string
 * @return 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.
 */
WS_DLL_PUBLIC
const uint8_t *ws_memmem(const void *haystack, size_t haystack_len,
                        const void *needle, size_t needle_len);

/**   @}
 *  @} */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __WMEM_STRUTL_H__ */

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */