[filesystem.c] Add a cast to aviod a warning with VisualStudio 2017.
[metze/wireshark/wip.git] / wsutil / 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  * 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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef _WS_STRTOI_H
26 #define _WS_STRTOI_H
27
28 #include <glib.h>
29
30 #include "ws_symbol_export.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35
36 /*
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.
47  */
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);
52
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);
57
58 /*
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.
69  */
70
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);
75
76 #ifdef __cplusplus
77 }
78 #endif /* __cplusplus */
79
80 #endif
81
82 /*
83  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
84  *
85  * Local variables:
86  * c-basic-offset: 4
87  * tab-width: 8
88  * indent-tabs-mode: t
89  * End:
90  *
91  * vi: set shiftwidth=4 tabstop=8 noexpandtab:
92  * :indentSize=4:tabSize=8:noTabs=false:
93  */