2 * Utilities to convert strings to integers
4 * Copyright 2016, Dario Lombardo
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "ws_symbol_export.h"
34 #endif /* __cplusplus */
37 * \brief Convert a decimal string to a signed/unsigned int, with error checks.
38 * \param str The string to convert
39 * \param endptr A pointer that will store a pointer to the first invalid
40 * character in str, allowing a number to be parsed even if there is trailing
41 * whitespace. If NULL, then the string is assumed to contain only valid
42 * characters (or it will error out).
43 * \param cint The converted integer
44 * \return TRUE if the conversion succeeds, FALSE otherwise.
45 * On error, errno is set to EINVAL for unrecognized input and ERANGE
46 * if the resulting number does not fit in the type.
48 WS_DLL_PUBLIC gboolean ws_strtoi64(const gchar* str, const gchar** endptr, gint64* cint);
49 WS_DLL_PUBLIC gboolean ws_strtoi32(const gchar* str, const gchar** endptr, gint32* cint);
50 WS_DLL_PUBLIC gboolean ws_strtoi16(const gchar* str, const gchar** endptr, gint16* cint);
51 WS_DLL_PUBLIC gboolean ws_strtoi8 (const gchar* str, const gchar** endptr, gint8* cint);
53 WS_DLL_PUBLIC gboolean ws_strtou64(const gchar* str, const gchar** endptr, guint64* cint);
54 WS_DLL_PUBLIC gboolean ws_strtou32(const gchar* str, const gchar** endptr, guint32* cint);
55 WS_DLL_PUBLIC gboolean ws_strtou16(const gchar* str, const gchar** endptr, guint16* cint);
56 WS_DLL_PUBLIC gboolean ws_strtou8 (const gchar* str, const gchar** endptr, guint8* cint);
59 * \brief Convert a hexadecimal string to an unsigned int, with error checks.
60 * \param str The string to convert
61 * \param endptr A pointer that will store a pointer to the first invalid
62 * character in str, allowing a number to be parsed even if there is trailing
63 * whitespace. If NULL, then the string is assumed to contain only valid
64 * characters (or it will error out).
65 * \param cint The converted integer
66 * \return TRUE if the conversion succeeds, FALSE otherwise.
67 * On error, errno is set to EINVAL for unrecognized input and ERANGE
68 * if the resulting number does not fit in the type.
71 WS_DLL_PUBLIC gboolean ws_hexstrtou64(const gchar* str, const gchar** endptr, guint64* cint);
72 WS_DLL_PUBLIC gboolean ws_hexstrtou32(const gchar* str, const gchar** endptr, guint32* cint);
73 WS_DLL_PUBLIC gboolean ws_hexstrtou16(const gchar* str, const gchar** endptr, guint16* cint);
74 WS_DLL_PUBLIC gboolean ws_hexstrtou8 (const gchar* str, const gchar** endptr, guint8* cint);
78 #endif /* __cplusplus */
83 * Editor modelines - https://www.wireshark.org/tools/modelines.html
91 * vi: set shiftwidth=4 tabstop=8 noexpandtab:
92 * :indentSize=4:tabSize=8:noTabs=false: