Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
strtoi.h
Go to the documentation of this file.
1
13#ifndef _WS_STRTOI_H
14#define _WS_STRTOI_H
15
16#include <stdbool.h>
17#include <inttypes.h>
18
19#include "ws_symbol_export.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25/*
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.
36 */
37WS_DLL_PUBLIC bool ws_strtoi64(const char* str, const char** endptr, int64_t* cint);
38WS_DLL_PUBLIC bool ws_strtoi32(const char* str, const char** endptr, int32_t* cint);
39WS_DLL_PUBLIC bool ws_strtoi16(const char* str, const char** endptr, int16_t* cint);
40WS_DLL_PUBLIC bool ws_strtoi8 (const char* str, const char** endptr, int8_t* cint);
41WS_DLL_PUBLIC bool ws_strtoi (const char* str, const char** endptr, int* cint);
42
43WS_DLL_PUBLIC bool ws_strtou64(const char* str, const char** endptr, uint64_t* cint);
44WS_DLL_PUBLIC bool ws_strtou32(const char* str, const char** endptr, uint32_t* cint);
45WS_DLL_PUBLIC bool ws_strtou16(const char* str, const char** endptr, uint16_t* cint);
46WS_DLL_PUBLIC bool ws_strtou8 (const char* str, const char** endptr, uint8_t* cint);
47WS_DLL_PUBLIC bool ws_strtou (const char* str, const char** endptr, unsigned* cint);
48
49/*
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.
60 */
61
62WS_DLL_PUBLIC bool ws_hexstrtou64(const char* str, const char** endptr, uint64_t* cint);
63WS_DLL_PUBLIC bool ws_hexstrtou32(const char* str, const char** endptr, uint32_t* cint);
64WS_DLL_PUBLIC bool ws_hexstrtou16(const char* str, const char** endptr, uint16_t* cint);
65WS_DLL_PUBLIC bool ws_hexstrtou8 (const char* str, const char** endptr, uint8_t* cint);
66WS_DLL_PUBLIC bool ws_hexstrtou (const char* str, const char** endptr, unsigned* cint);
67
68/*
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.
83 */
84
85WS_DLL_PUBLIC bool ws_basestrtou64(const char* str, const char** endptr, uint64_t* cint, int base);
86WS_DLL_PUBLIC bool ws_basestrtou32(const char* str, const char** endptr, uint32_t* cint, int base);
87WS_DLL_PUBLIC bool ws_basestrtou16(const char* str, const char** endptr, uint16_t* cint, int base);
88WS_DLL_PUBLIC bool ws_basestrtou8 (const char* str, const char** endptr, uint8_t* cint, int base);
89WS_DLL_PUBLIC bool ws_basestrtou (const char* str, const char** endptr, unsigned* cint, int base);
90
91#ifdef __cplusplus
92}
93#endif /* __cplusplus */
94
95#endif
96
97/*
98 * Editor modelines - https://www.wireshark.org/tools/modelines.html
99 *
100 * Local variables:
101 * c-basic-offset: 4
102 * tab-width: 8
103 * indent-tabs-mode: t
104 * End:
105 *
106 * vi: set shiftwidth=4 tabstop=8 noexpandtab:
107 * :indentSize=4:tabSize=8:noTabs=false:
108 */