Revert "UNUSED enc_key_id_{equal,hash}"
[wireshark-sm.git] / wsutil / strtoi.h
blob04fe802ed82cda822436b560f9a88cc1879baa1d
1 /** @file
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 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef _WS_STRTOI_H
14 #define _WS_STRTOI_H
16 #include <stdbool.h>
17 #include <inttypes.h>
19 #include "ws_symbol_export.h"
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
26 * \brief Convert a decimal string to a signed/unsigned int, with error checks.
27 * \param str The string to convert
28 * \param endptr A pointer that will store a pointer to the first invalid
29 * character in str, allowing a number to be parsed even if there is trailing
30 * whitespace. If NULL, then the string is assumed to contain only valid
31 * characters (or it will error out).
32 * \param cint The converted integer
33 * \return true if the conversion succeeds, false otherwise.
34 * On error, errno is set to EINVAL for unrecognized input and ERANGE
35 * if the resulting number does not fit in the type.
37 WS_DLL_PUBLIC bool ws_strtoi64(const char* str, const char** endptr, int64_t* cint);
38 WS_DLL_PUBLIC bool ws_strtoi32(const char* str, const char** endptr, int32_t* cint);
39 WS_DLL_PUBLIC bool ws_strtoi16(const char* str, const char** endptr, int16_t* cint);
40 WS_DLL_PUBLIC bool ws_strtoi8 (const char* str, const char** endptr, int8_t* cint);
41 WS_DLL_PUBLIC bool ws_strtoi (const char* str, const char** endptr, int* cint);
43 WS_DLL_PUBLIC bool ws_strtou64(const char* str, const char** endptr, uint64_t* cint);
44 WS_DLL_PUBLIC bool ws_strtou32(const char* str, const char** endptr, uint32_t* cint);
45 WS_DLL_PUBLIC bool ws_strtou16(const char* str, const char** endptr, uint16_t* cint);
46 WS_DLL_PUBLIC bool ws_strtou8 (const char* str, const char** endptr, uint8_t* cint);
47 WS_DLL_PUBLIC bool ws_strtou (const char* str, const char** endptr, unsigned* cint);
50 * \brief Convert a hexadecimal string to an unsigned int, with error checks.
51 * \param str The string to convert
52 * \param endptr A pointer that will store a pointer to the first invalid
53 * character in str, allowing a number to be parsed even if there is trailing
54 * whitespace. If NULL, then the string is assumed to contain only valid
55 * characters (or it will error out).
56 * \param cint The converted integer
57 * \return true if the conversion succeeds, false otherwise.
58 * On error, errno is set to EINVAL for unrecognized input and ERANGE
59 * if the resulting number does not fit in the type.
62 WS_DLL_PUBLIC bool ws_hexstrtou64(const char* str, const char** endptr, uint64_t* cint);
63 WS_DLL_PUBLIC bool ws_hexstrtou32(const char* str, const char** endptr, uint32_t* cint);
64 WS_DLL_PUBLIC bool ws_hexstrtou16(const char* str, const char** endptr, uint16_t* cint);
65 WS_DLL_PUBLIC bool ws_hexstrtou8 (const char* str, const char** endptr, uint8_t* cint);
66 WS_DLL_PUBLIC bool ws_hexstrtou (const char* str, const char** endptr, unsigned* cint);
69 * \brief Convert a string in the specified base to an unsigned int, with
70 * error checks.
71 * \param str The string to convert
72 * \param endptr A pointer that will store a pointer to the first invalid
73 * character in str, allowing a number to be parsed even if there is trailing
74 * whitespace. If NULL, then the string is assumed to contain only valid
75 * characters (or it will error out).
76 * \param cint The converted integer
77 * \param base The base for the integer; 0 means "if it begins with 0x,
78 * it's hex, otherwise if it begins with 0, it's octal, otherwise it's
79 * decimal".
80 * \return true if the conversion succeeds, false otherwise.
81 * On error, errno is set to EINVAL for unrecognized input and ERANGE
82 * if the resulting number does not fit in the type.
85 WS_DLL_PUBLIC bool ws_basestrtou64(const char* str, const char** endptr, uint64_t* cint, int base);
86 WS_DLL_PUBLIC bool ws_basestrtou32(const char* str, const char** endptr, uint32_t* cint, int base);
87 WS_DLL_PUBLIC bool ws_basestrtou16(const char* str, const char** endptr, uint16_t* cint, int base);
88 WS_DLL_PUBLIC bool ws_basestrtou8 (const char* str, const char** endptr, uint8_t* cint, int base);
89 WS_DLL_PUBLIC bool ws_basestrtou (const char* str, const char** endptr, unsigned* cint, int base);
91 #ifdef __cplusplus
93 #endif /* __cplusplus */
95 #endif
98 * Editor modelines - https://www.wireshark.org/tools/modelines.html
100 * Local variables:
101 * c-basic-offset: 4
102 * tab-width: 8
103 * indent-tabs-mode: t
104 * End:
106 * vi: set shiftwidth=4 tabstop=8 noexpandtab:
107 * :indentSize=4:tabSize=8:noTabs=false: