Changeset 48751ab in rtems for cpukit/libmisc/stringto


Ignore:
Timestamp:
Jul 23, 2009, 2:32:34 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 5, master
Children:
7611ed8e
Parents:
73dfaf8
Message:

2009-07-23 Joel Sherrill <joel.sherrill@…>

  • libmisc/Makefile.am, libmisc/shell/main_chmod.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c, libmisc/shell/shell_script.c, libmisc/stringto/stringto.h, libmisc/stringto/stringto_template.h: Convert return type from bool to rtems_status_code and add rtems_string_to_pointer. Perform associated clean up and changes for return type change.
  • libmisc/stringto/stringtopointer.c: New file.
Location:
cpukit/libmisc/stringto
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/stringto/stringto.h

    r73dfaf8 r48751ab  
    1313#define __STRING_TO_A_TYPE_h__
    1414
     15#include <rtems.h>
     16
     17/**
     18 *  @brief Convert String to Pointer (with validation)
     19 *
     20 *  This method converts a string to a pointer (void *) with
     21 *  basic numeric validation.
     22 *
     23 *  @param[in] s is the string to convert
     24 *  @param[in] n points to the variable to place the converted output in
     25 *  @param[in] endptr is used to keep track of the position in the string
     26 *
     27 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     28 *          and *n is filled in.  Otherwise, the status indicates the
     29 *          source of the error.
     30 */
     31rtems_status_code rtems_string_to_pointer(
     32  const char     *s,
     33  void          **n,
     34  char          **endptr
     35);
     36
    1537/**
    1638 *  @brief Convert String to Unsigned Character (with validation)
     
    2446 *  @param[in] base is the expected base of the number
    2547 *
    26  *  @return This method returns true on successful conversion and *n is
    27  *          filled in.
    28  */
    29 bool rtems_string_to_unsigned_char(
     48 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     49 *          and *n is filled in.  Otherwise, the status indicates the
     50 *          source of the error.
     51 */
     52rtems_status_code rtems_string_to_unsigned_char(
    3053  const char     *s,
    3154  unsigned char  *n,
     
    4467 *  @param[in] base is the expected base of the number
    4568 *
    46  *  @return This method returns true on successful conversion and *n is
    47  *          filled in.
    48  */
    49 bool rtems_string_to_int(
     69 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     70 *          and *n is filled in.  Otherwise, the status indicates the
     71 *          source of the error.
     72 */
     73rtems_status_code rtems_string_to_int(
    5074  const char  *s,
    5175  int         *n,
     
    6589 *  @param[in] base is the expected base of the number
    6690 *
    67  *  @return This method returns true on successful conversion and *n is
    68  *          filled in.
    69  */
    70 bool rtems_string_to_long(
     91 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     92 *          and *n is filled in.  Otherwise, the status indicates the
     93 *          source of the error.
     94 */
     95rtems_status_code rtems_string_to_long(
    7196  const char  *s,
    7297  long        *n,
     
    86111 *  @param[in] base is the expected base of the number
    87112 *
    88  *  @return This method returns true on successful conversion and *n is
    89  *          filled in.
    90  */
    91 bool rtems_string_to_unsigned_long(
     113 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     114 *          and *n is filled in.  Otherwise, the status indicates the
     115 *          source of the error.
     116 */
     117rtems_status_code rtems_string_to_unsigned_long(
    92118  const char     *s,
    93119  unsigned long  *n,
     
    107133 *  @param[in] base is the expected base of the number
    108134 *
    109  *  @return This method returns true on successful conversion and *n is
    110  *          filled in.
    111  */
    112 bool rtems_string_to_long_long(
     135 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     136 *          and *n is filled in.  Otherwise, the status indicates the
     137 *          source of the error.
     138 */
     139rtems_status_code rtems_string_to_long_long(
    113140  const char  *s,
    114141  long long   *n,
     
    128155 *  @param[in] base is the expected base of the number
    129156 *
    130  *  @return This method returns true on successful conversion and *n is
    131  *          filled in.
    132  */
    133 bool rtems_string_to_unsigned_long_long(
     157 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     158 *          and *n is filled in.  Otherwise, the status indicates the
     159 *          source of the error.
     160 */
     161rtems_status_code rtems_string_to_unsigned_long_long(
    134162  const char           *s,
    135163  unsigned long long   *n,
     
    147175 *  @param[in] endptr is used to keep track of the position in the string
    148176 *
    149  *  @return This method returns true on successful conversion and *n is
    150  *          filled in.
    151  */
    152 bool rtems_string_to_float(
     177 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     178 *          and *n is filled in.  Otherwise, the status indicates the
     179 *          source of the error.
     180 */
     181rtems_status_code rtems_string_to_float(
    153182  const char   *s,
    154183  float        *n,
     
    165194 *  @param[in] endptr is used to keep track of the position in the string
    166195 *
    167  *  @return This method returns true on successful conversion and *n is
    168  *          filled in.
    169  */
    170 bool rtems_string_to_double(
     196 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     197 *          and *n is filled in.  Otherwise, the status indicates the
     198 *          source of the error.
     199 */
     200rtems_status_code rtems_string_to_double(
    171201  const char   *s,
    172202  double       *n,
  • cpukit/libmisc/stringto/stringto_template.h

    r73dfaf8 r48751ab  
    1010 */
    1111
     12#include <rtems/stringto.h>
     13
    1214#include <errno.h>
    1315#include <stdlib.h>
     
    1517#include <stdbool.h>
    1618
    17 #include <math.h>
     19/*
     20 *  If we are doing floating point conversion, then we need math.h
     21 */
     22#if defined(STRING_TO_FLOAT)
     23  #include <math.h>
     24#endif
     25
     26#include <rtems.h>
    1827
    1928/*
     
    2130 * it and should NOT be protected against multiple inclusions.
    2231 */
     32
     33#if defined(STRING_TO_POINTER)
     34  #define STRING_TO_INTEGER
     35#endif
    2336
    2437#if !defined(STRING_TO_FLOAT) && !defined(STRING_TO_INTEGER)
     
    5366#endif
    5467
    55 bool STRING_TO_NAME (
     68#if !defined(STRING_TO_INPUT_TYPE)
     69  #define STRING_TO_INPUT_TYPE STRING_TO_TYPE
     70#endif
     71
     72rtems_status_code STRING_TO_NAME (
    5673  const char      *s,
    5774  STRING_TO_TYPE  *n,
    5875  char           **endptr
    59   #if defined(STRING_TO_INTEGER)
     76  #if defined(STRING_TO_INTEGER) && !defined(STRING_TO_POINTER)
    6077    ,
    6178    int              base
     
    6380)
    6481{
    65   STRING_TO_TYPE  result;
    66   char           *end;
     82  STRING_TO_INPUT_TYPE  result;
     83  char                 *end;
    6784
    6885  if ( !n )
    69     return false;
     86    return RTEMS_INVALID_ADDRESS;
    7087
    7188  errno = 0;
     
    7491  #ifdef STRING_TO_FLOAT
    7592    result = STRING_TO_METHOD( s, &end );
     93  #elif defined(STRING_TO_POINTER)
     94    result = STRING_TO_METHOD( s, &end, 16 );
    7695  #elif defined(STRING_TO_INTEGER)
    7796    result = STRING_TO_METHOD( s, &end, base );
     
    84103  /* nothing was converted */
    85104  if ( end == s )
    86     return false;
     105    return RTEMS_NOT_DEFINED;
    87106
    88107  /* there was a conversion error */
    89108  if ( (result == ZERO) && errno )
    90     return false;
     109    return RTEMS_INVALID_NUMBER;
    91110
    92111  #ifdef STRING_TO_MAX
    93112    /* there was an overflow */
    94113    if ( (result == STRING_TO_MAX) && (errno == ERANGE))
    95       return false;
     114      return RTEMS_INVALID_NUMBER;
    96115  #endif
    97116
     
    99118    /* there was an underflow */
    100119    if ( (result == STRING_TO_MIN) && (errno == ERANGE))
    101       return false;
     120      return RTEMS_INVALID_NUMBER;
    102121  #endif
    103122
    104123  *n = (STRING_TO_TYPE) result;
    105   return true;
     124  return RTEMS_SUCCESSFUL;
    106125}
    107126
Note: See TracChangeset for help on using the changeset viewer.