Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup libmisc_conv_help
0007  *
0008  * @brief Convert String to Pointer (with validation)
0009  *
0010  * This file defines the interface to a set of string conversion helpers.
0011  */
0012 
0013 /*
0014  * COPYRIGHT (c) 2009-2011.
0015  * On-Line Applications Research Corporation (OAR).
0016  *
0017  * Redistribution and use in source and binary forms, with or without
0018  * modification, are permitted provided that the following conditions
0019  * are met:
0020  * 1. Redistributions of source code must retain the above copyright
0021  *    notice, this list of conditions and the following disclaimer.
0022  * 2. Redistributions in binary form must reproduce the above copyright
0023  *    notice, this list of conditions and the following disclaimer in the
0024  *    documentation and/or other materials provided with the distribution.
0025  *
0026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0036  * POSSIBILITY OF SUCH DAMAGE.
0037  */
0038 
0039 #ifndef _RTEMS_STRINGTO_H
0040 #define _RTEMS_STRINGTO_H
0041 /**
0042  *  @defgroup libmisc_conv_help Conversion Helpers
0043  *
0044  *  @ingroup RTEMSAPIClassic
0045  */
0046 /**@{*/
0047 
0048 #include <rtems.h>
0049 
0050 /**
0051  * @brief Convert String to Pointer (with validation).
0052  *
0053  * This method converts a string to a pointer (void *) with
0054  * basic numeric validation.
0055  *
0056  * @param[in] s is the string to convert
0057  * @param[in] n points to the variable to place the converted output in
0058  * @param[in] endptr is used to keep track of the position in the string
0059  *
0060  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0061  *         and *n is filled in. Otherwise, the status indicates the
0062  *         source of the error.
0063  */
0064 rtems_status_code rtems_string_to_pointer(
0065   const char     *s,
0066   void          **n,
0067   char          **endptr
0068 );
0069 
0070 /**
0071  * @brief Convert String to Unsigned Character (with validation).
0072  *
0073  * This method converts a string to an unsigned character with
0074  * range validation.
0075  *
0076  * @param[in] s is the string to convert
0077  * @param[in] n points to the variable to place the converted output in
0078  * @param[in] endptr is used to keep track of the position in the string
0079  * @param[in] base is the expected base of the number
0080  *
0081  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0082  *         and *n is filled in. Otherwise, the status indicates the
0083  *         source of the error.
0084  */
0085 rtems_status_code rtems_string_to_unsigned_char(
0086   const char     *s,
0087   unsigned char  *n,
0088   char          **endptr,
0089   int             base
0090 );
0091 
0092 /**
0093  * @brief Convert String to Int (with validation).
0094  *
0095  * This method converts a string to an int with range validation.
0096  *
0097  * @param[in] s is the string to convert
0098  * @param[in] n points to the variable to place the converted output in
0099  * @param[in] endptr is used to keep track of the position in the string
0100  * @param[in] base is the expected base of the number
0101  *
0102  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0103  *         and *n is filled in. Otherwise, the status indicates the
0104  *         source of the error.
0105  */
0106 rtems_status_code rtems_string_to_int(
0107   const char  *s,
0108   int         *n,
0109   char       **endptr,
0110   int          base
0111 );
0112 
0113 /**
0114  * @brief Convert String to Unsigned Int (with validation).
0115  *
0116  * This method converts a string to an unsigned int with range validation.
0117  *
0118  * @param[in] s is the string to convert
0119  * @param[in] n points to the variable to place the converted output in
0120  * @param[in] endptr is used to keep track of the position in the string
0121  * @param[in] base is the expected base of the number
0122  *
0123  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0124  *         and *n is filled in. Otherwise, the status indicates the
0125  *         source of the error.
0126  */
0127 rtems_status_code rtems_string_to_unsigned_int(
0128   const char    *s,
0129   unsigned int  *n,
0130   char         **endptr,
0131   int            base
0132 );
0133 
0134 /**
0135  * @brief Convert String to Long (with validation).
0136  *
0137  * This method converts a string to a long with
0138  * range validation.
0139  *
0140  * @param[in] s is the string to convert
0141  * @param[in] n points to the variable to place the converted output in
0142  * @param[in] endptr is used to keep track of the position in the string
0143  * @param[in] base is the expected base of the number
0144  *
0145  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0146  *         and *n is filled in. Otherwise, the status indicates the
0147  *         source of the error.
0148  */
0149 rtems_status_code rtems_string_to_long(
0150   const char  *s,
0151   long        *n,
0152   char       **endptr,
0153   int          base
0154 );
0155 
0156 /**
0157  * @brief Convert String to Unsigned Long (with validation).
0158  *
0159  * This method converts a string to an unsigned long with
0160  * range validation.
0161  *
0162  * @param[in] s is the string to convert
0163  * @param[in] n points to the variable to place the converted output in
0164  * @param[in] endptr is used to keep track of the position in the string
0165  * @param[in] base is the expected base of the number
0166  *
0167  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0168  *         and *n is filled in. Otherwise, the status indicates the
0169  *         source of the error.
0170  */
0171 rtems_status_code rtems_string_to_unsigned_long(
0172   const char     *s,
0173   unsigned long  *n,
0174   char          **endptr,
0175   int             base
0176 );
0177 
0178 /**
0179  * @brief Convert String to Long Long (with validation).
0180  *
0181  * This method converts a string to a long long with
0182  * range validation.
0183  *
0184  * @param[in] s is the string to convert
0185  * @param[in] n points to the variable to place the converted output in
0186  * @param[in] endptr is used to keep track of the position in the string
0187  * @param[in] base is the expected base of the number
0188  *
0189  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0190  *         and *n is filled in. Otherwise, the status indicates the
0191  *         source of the error.
0192  */
0193 rtems_status_code rtems_string_to_long_long(
0194   const char  *s,
0195   long long   *n,
0196   char       **endptr,
0197   int          base
0198 );
0199 
0200 /**
0201  * @brief Convert String to Unsigned Long Long (with validation).
0202  *
0203  * This method converts a string to an unsigned character with
0204  * range validation.
0205  *
0206  * @param[in] s is the string to convert
0207  * @param[in] n points to the variable to place the converted output in
0208  * @param[in] endptr is used to keep track of the position in the string
0209  * @param[in] base is the expected base of the number
0210  *
0211  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0212  *         and *n is filled in. Otherwise, the status indicates the
0213  *         source of the error.
0214  */
0215 rtems_status_code rtems_string_to_unsigned_long_long(
0216   const char           *s,
0217   unsigned long long   *n,
0218   char                **endptr,
0219   int                   base
0220 );
0221 
0222 /**
0223  * @brief Convert String to Float (with validation).
0224  *
0225  * This method converts a string to a float with range validation.
0226  *
0227  * @param[in] s is the string to convert
0228  * @param[in] n points to the variable to place the converted output in
0229  * @param[in] endptr is used to keep track of the position in the string
0230  *
0231  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0232  *         and *n is filled in. Otherwise, the status indicates the
0233  *         source of the error.
0234  */
0235 rtems_status_code rtems_string_to_float(
0236   const char   *s,
0237   float        *n,
0238   char        **endptr
0239 );
0240 
0241 /**
0242  * @brief Convert String to Double (with validation).
0243  *
0244  * This method converts a string to a double with range validation.
0245  *
0246  * @param[in] s is the string to convert
0247  * @param[in] n points to the variable to place the converted output in
0248  * @param[in] endptr is used to keep track of the position in the string
0249  *
0250  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0251  *         and *n is filled in. Otherwise, the status indicates the
0252  *         source of the error.
0253  */
0254 rtems_status_code rtems_string_to_double(
0255   const char   *s,
0256   double       *n,
0257   char        **endptr
0258 );
0259 
0260 /**
0261  * @brief Convert String to long double (with validation).
0262  *
0263  * This method converts a string to a long double with range validation.
0264  *
0265  * @param[in] s is the string to convert
0266  * @param[in] n points to the variable to place the converted output in
0267  * @param[in] endptr is used to keep track of the position in the string
0268  *
0269  * @retval This method returns RTEMS_SUCCESSFUL on successful conversion
0270  *         and *n is filled in. Otherwise, the status indicates the
0271  *         source of the error.
0272  */
0273 rtems_status_code rtems_string_to_long_double(
0274   const char   *s,
0275   long double  *n,
0276   char        **endptr
0277 );
0278 
0279 #endif
0280 /**@}*/