Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
strtoi.h
1 /* strtoi.h
2  * Utilities to convert strings to integers
3  *
4  * Copyright 2016, Dario Lombardo
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 
13 #ifndef _WS_STRTOI_H
14 #define _WS_STRTOI_H
15 
16 #include <glib.h>
17 
18 #include "ws_symbol_export.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 /*
25  * \brief Convert a decimal string to a signed/unsigned int, with error checks.
26  * \param str The string to convert
27  * \param endptr A pointer that will store a pointer to the first invalid
28  * character in str, allowing a number to be parsed even if there is trailing
29  * whitespace. If NULL, then the string is assumed to contain only valid
30  * characters (or it will error out).
31  * \param cint The converted integer
32  * \return TRUE if the conversion succeeds, FALSE otherwise.
33  * On error, errno is set to EINVAL for unrecognized input and ERANGE
34  * if the resulting number does not fit in the type.
35  */
36 WS_DLL_PUBLIC gboolean ws_strtoi64(const gchar* str, const gchar** endptr, gint64* cint);
37 WS_DLL_PUBLIC gboolean ws_strtoi32(const gchar* str, const gchar** endptr, gint32* cint);
38 WS_DLL_PUBLIC gboolean ws_strtoi16(const gchar* str, const gchar** endptr, gint16* cint);
39 WS_DLL_PUBLIC gboolean ws_strtoi8 (const gchar* str, const gchar** endptr, gint8* cint);
40 
41 WS_DLL_PUBLIC gboolean ws_strtou64(const gchar* str, const gchar** endptr, guint64* cint);
42 WS_DLL_PUBLIC gboolean ws_strtou32(const gchar* str, const gchar** endptr, guint32* cint);
43 WS_DLL_PUBLIC gboolean ws_strtou16(const gchar* str, const gchar** endptr, guint16* cint);
44 WS_DLL_PUBLIC gboolean ws_strtou8 (const gchar* str, const gchar** endptr, guint8* cint);
45 
46 /*
47  * \brief Convert a hexadecimal string to an unsigned int, with error checks.
48  * \param str The string to convert
49  * \param endptr A pointer that will store a pointer to the first invalid
50  * character in str, allowing a number to be parsed even if there is trailing
51  * whitespace. If NULL, then the string is assumed to contain only valid
52  * characters (or it will error out).
53  * \param cint The converted integer
54  * \return TRUE if the conversion succeeds, FALSE otherwise.
55  * On error, errno is set to EINVAL for unrecognized input and ERANGE
56  * if the resulting number does not fit in the type.
57  */
58 
59 WS_DLL_PUBLIC gboolean ws_hexstrtou64(const gchar* str, const gchar** endptr, guint64* cint);
60 WS_DLL_PUBLIC gboolean ws_hexstrtou32(const gchar* str, const gchar** endptr, guint32* cint);
61 WS_DLL_PUBLIC gboolean ws_hexstrtou16(const gchar* str, const gchar** endptr, guint16* cint);
62 WS_DLL_PUBLIC gboolean ws_hexstrtou8 (const gchar* str, const gchar** endptr, guint8* cint);
63 
64 #ifdef __cplusplus
65 }
66 #endif /* __cplusplus */
67 
68 #endif
69 
70 /*
71  * Editor modelines - https://www.wireshark.org/tools/modelines.html
72  *
73  * Local variables:
74  * c-basic-offset: 4
75  * tab-width: 8
76  * indent-tabs-mode: t
77  * End:
78  *
79  * vi: set shiftwidth=4 tabstop=8 noexpandtab:
80  * :indentSize=4:tabSize=8:noTabs=false:
81  */