1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup libmisc_conv_help |
---|
7 | * |
---|
8 | * @brief Convert String to Pointer (with validation) |
---|
9 | * |
---|
10 | * This file defines the interface to a set of string conversion helpers. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * COPYRIGHT (c) 2009-2011. |
---|
15 | * On-Line Applications Research Corporation (OAR). |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | #ifndef _RTEMS_STRINGTO_H |
---|
40 | #define _RTEMS_STRINGTO_H |
---|
41 | /** |
---|
42 | * @defgroup libmisc_conv_help Conversion Helpers |
---|
43 | * |
---|
44 | * @ingroup RTEMSAPIClassic |
---|
45 | */ |
---|
46 | /**@{*/ |
---|
47 | |
---|
48 | #include <rtems.h> |
---|
49 | |
---|
50 | /** |
---|
51 | * @brief Convert String to Pointer (with validation). |
---|
52 | * |
---|
53 | * This method converts a string to a pointer (void *) with |
---|
54 | * basic numeric validation. |
---|
55 | * |
---|
56 | * @param[in] s is the string to convert |
---|
57 | * @param[in] n points to the variable to place the converted output in |
---|
58 | * @param[in] endptr is used to keep track of the position in the string |
---|
59 | * |
---|
60 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
61 | * and *n is filled in. Otherwise, the status indicates the |
---|
62 | * source of the error. |
---|
63 | */ |
---|
64 | rtems_status_code rtems_string_to_pointer( |
---|
65 | const char *s, |
---|
66 | void **n, |
---|
67 | char **endptr |
---|
68 | ); |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief Convert String to Unsigned Character (with validation). |
---|
72 | * |
---|
73 | * This method converts a string to an unsigned character with |
---|
74 | * range validation. |
---|
75 | * |
---|
76 | * @param[in] s is the string to convert |
---|
77 | * @param[in] n points to the variable to place the converted output in |
---|
78 | * @param[in] endptr is used to keep track of the position in the string |
---|
79 | * @param[in] base is the expected base of the number |
---|
80 | * |
---|
81 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
82 | * and *n is filled in. Otherwise, the status indicates the |
---|
83 | * source of the error. |
---|
84 | */ |
---|
85 | rtems_status_code rtems_string_to_unsigned_char( |
---|
86 | const char *s, |
---|
87 | unsigned char *n, |
---|
88 | char **endptr, |
---|
89 | int base |
---|
90 | ); |
---|
91 | |
---|
92 | /** |
---|
93 | * @brief Convert String to Int (with validation). |
---|
94 | * |
---|
95 | * This method converts a string to an int with range validation. |
---|
96 | * |
---|
97 | * @param[in] s is the string to convert |
---|
98 | * @param[in] n points to the variable to place the converted output in |
---|
99 | * @param[in] endptr is used to keep track of the position in the string |
---|
100 | * @param[in] base is the expected base of the number |
---|
101 | * |
---|
102 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
103 | * and *n is filled in. Otherwise, the status indicates the |
---|
104 | * source of the error. |
---|
105 | */ |
---|
106 | rtems_status_code rtems_string_to_int( |
---|
107 | const char *s, |
---|
108 | int *n, |
---|
109 | char **endptr, |
---|
110 | int base |
---|
111 | ); |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief Convert String to Unsigned Int (with validation). |
---|
115 | * |
---|
116 | * This method converts a string to an unsigned int with range validation. |
---|
117 | * |
---|
118 | * @param[in] s is the string to convert |
---|
119 | * @param[in] n points to the variable to place the converted output in |
---|
120 | * @param[in] endptr is used to keep track of the position in the string |
---|
121 | * @param[in] base is the expected base of the number |
---|
122 | * |
---|
123 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
124 | * and *n is filled in. Otherwise, the status indicates the |
---|
125 | * source of the error. |
---|
126 | */ |
---|
127 | rtems_status_code rtems_string_to_unsigned_int( |
---|
128 | const char *s, |
---|
129 | unsigned int *n, |
---|
130 | char **endptr, |
---|
131 | int base |
---|
132 | ); |
---|
133 | |
---|
134 | /** |
---|
135 | * @brief Convert String to Long (with validation). |
---|
136 | * |
---|
137 | * This method converts a string to a long with |
---|
138 | * range validation. |
---|
139 | * |
---|
140 | * @param[in] s is the string to convert |
---|
141 | * @param[in] n points to the variable to place the converted output in |
---|
142 | * @param[in] endptr is used to keep track of the position in the string |
---|
143 | * @param[in] base is the expected base of the number |
---|
144 | * |
---|
145 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
146 | * and *n is filled in. Otherwise, the status indicates the |
---|
147 | * source of the error. |
---|
148 | */ |
---|
149 | rtems_status_code rtems_string_to_long( |
---|
150 | const char *s, |
---|
151 | long *n, |
---|
152 | char **endptr, |
---|
153 | int base |
---|
154 | ); |
---|
155 | |
---|
156 | /** |
---|
157 | * @brief Convert String to Unsigned Long (with validation). |
---|
158 | * |
---|
159 | * This method converts a string to an unsigned long with |
---|
160 | * range validation. |
---|
161 | * |
---|
162 | * @param[in] s is the string to convert |
---|
163 | * @param[in] n points to the variable to place the converted output in |
---|
164 | * @param[in] endptr is used to keep track of the position in the string |
---|
165 | * @param[in] base is the expected base of the number |
---|
166 | * |
---|
167 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
168 | * and *n is filled in. Otherwise, the status indicates the |
---|
169 | * source of the error. |
---|
170 | */ |
---|
171 | rtems_status_code rtems_string_to_unsigned_long( |
---|
172 | const char *s, |
---|
173 | unsigned long *n, |
---|
174 | char **endptr, |
---|
175 | int base |
---|
176 | ); |
---|
177 | |
---|
178 | /** |
---|
179 | * @brief Convert String to Long Long (with validation). |
---|
180 | * |
---|
181 | * This method converts a string to a long long with |
---|
182 | * range validation. |
---|
183 | * |
---|
184 | * @param[in] s is the string to convert |
---|
185 | * @param[in] n points to the variable to place the converted output in |
---|
186 | * @param[in] endptr is used to keep track of the position in the string |
---|
187 | * @param[in] base is the expected base of the number |
---|
188 | * |
---|
189 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
190 | * and *n is filled in. Otherwise, the status indicates the |
---|
191 | * source of the error. |
---|
192 | */ |
---|
193 | rtems_status_code rtems_string_to_long_long( |
---|
194 | const char *s, |
---|
195 | long long *n, |
---|
196 | char **endptr, |
---|
197 | int base |
---|
198 | ); |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief Convert String to Unsigned Long Long (with validation). |
---|
202 | * |
---|
203 | * This method converts a string to an unsigned character with |
---|
204 | * range validation. |
---|
205 | * |
---|
206 | * @param[in] s is the string to convert |
---|
207 | * @param[in] n points to the variable to place the converted output in |
---|
208 | * @param[in] endptr is used to keep track of the position in the string |
---|
209 | * @param[in] base is the expected base of the number |
---|
210 | * |
---|
211 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
212 | * and *n is filled in. Otherwise, the status indicates the |
---|
213 | * source of the error. |
---|
214 | */ |
---|
215 | rtems_status_code rtems_string_to_unsigned_long_long( |
---|
216 | const char *s, |
---|
217 | unsigned long long *n, |
---|
218 | char **endptr, |
---|
219 | int base |
---|
220 | ); |
---|
221 | |
---|
222 | /** |
---|
223 | * @brief Convert String to Float (with validation). |
---|
224 | * |
---|
225 | * This method converts a string to a float with range validation. |
---|
226 | * |
---|
227 | * @param[in] s is the string to convert |
---|
228 | * @param[in] n points to the variable to place the converted output in |
---|
229 | * @param[in] endptr is used to keep track of the position in the string |
---|
230 | * |
---|
231 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
232 | * and *n is filled in. Otherwise, the status indicates the |
---|
233 | * source of the error. |
---|
234 | */ |
---|
235 | rtems_status_code rtems_string_to_float( |
---|
236 | const char *s, |
---|
237 | float *n, |
---|
238 | char **endptr |
---|
239 | ); |
---|
240 | |
---|
241 | /** |
---|
242 | * @brief Convert String to Double (with validation). |
---|
243 | * |
---|
244 | * This method converts a string to a double with range validation. |
---|
245 | * |
---|
246 | * @param[in] s is the string to convert |
---|
247 | * @param[in] n points to the variable to place the converted output in |
---|
248 | * @param[in] endptr is used to keep track of the position in the string |
---|
249 | * |
---|
250 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
251 | * and *n is filled in. Otherwise, the status indicates the |
---|
252 | * source of the error. |
---|
253 | */ |
---|
254 | rtems_status_code rtems_string_to_double( |
---|
255 | const char *s, |
---|
256 | double *n, |
---|
257 | char **endptr |
---|
258 | ); |
---|
259 | |
---|
260 | /** |
---|
261 | * @brief Convert String to long double (with validation). |
---|
262 | * |
---|
263 | * This method converts a string to a long double with range validation. |
---|
264 | * |
---|
265 | * @param[in] s is the string to convert |
---|
266 | * @param[in] n points to the variable to place the converted output in |
---|
267 | * @param[in] endptr is used to keep track of the position in the string |
---|
268 | * |
---|
269 | * @retval This method returns RTEMS_SUCCESSFUL on successful conversion |
---|
270 | * and *n is filled in. Otherwise, the status indicates the |
---|
271 | * source of the error. |
---|
272 | */ |
---|
273 | rtems_status_code rtems_string_to_long_double( |
---|
274 | const char *s, |
---|
275 | long double *n, |
---|
276 | char **endptr |
---|
277 | ); |
---|
278 | |
---|
279 | #endif |
---|
280 | /**@}*/ |
---|