Back to home page

LXR

 
 

    


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

0001 /**
0002  * @file
0003  *
0004  * @ingroup libmisc_conv_help Conversion Helpers
0005  *
0006  * @brief Convert String to Pointer (with validation)
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 2009.
0011  *  On-Line Applications Research Corporation (OAR).
0012  *
0013  *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
0014  *
0015  *  The license and distribution terms for this file may be
0016  *  found in the file LICENSE in this distribution or at
0017  *  http://www.rtems.org/license/LICENSE.
0018  */
0019 
0020 #ifdef HAVE_CONFIG_H
0021 #include "config.h"
0022 #endif
0023 
0024 #include <errno.h>
0025 #include <stdlib.h>
0026 #include <limits.h>
0027 #include <stdint.h>
0028 
0029 #include <rtems/stringto.h>
0030 
0031 /*
0032  *  Instantiate an error checking wrapper for strtoul/strtoull (void *)
0033  */
0034 
0035 #if (UINTPTR_MAX == ULONG_MAX)
0036 #define STRTOFUNC(a,b,c)    rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
0037 #elif (UINTPTR_MAX == ULONG_LONG_MAX)
0038 #define STRTOFUNC(a,b,c)    rtems_string_to_unsigned_long_long(a, (unsigned long long*) b, c, 0)
0039 #elif (UINTPTR_MAX == UINT_MAX)
0040 #define STRTOFUNC(a,b,c)    rtems_string_to_unsigned_int(a, (unsigned int*) b, c, 0)
0041 #else
0042 /* Fallback to unsigned long */
0043 #define STRTOFUNC(a,b,c)    rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
0044 #endif
0045 
0046 rtems_status_code rtems_string_to_pointer (
0047   const char *s,
0048   void **n,
0049   char **endptr
0050 )
0051 {
0052   return STRTOFUNC( s, n, endptr );
0053 }