Changeset 48751ab in rtems


Ignore:
Timestamp:
Jul 23, 2009, 2:32:34 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 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
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r73dfaf8 r48751ab  
     12009-07-23      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libmisc/Makefile.am, libmisc/shell/main_chmod.c,
     4        libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
     5        libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
     6        libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
     7        libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
     8        libmisc/shell/shell_script.c, libmisc/stringto/stringto.h,
     9        libmisc/stringto/stringto_template.h: Convert return type from bool
     10        to rtems_status_code and add rtems_string_to_pointer. Perform
     11        associated clean up and changes for return type change.
     12        * libmisc/stringto/stringtopointer.c: New file.
     13
    1142009-07-22      Joel Sherrill <joel.sherrill@OARcorp.com>
    215
  • cpukit/libmisc/Makefile.am

    r73dfaf8 r48751ab  
    132132libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \
    133133    stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \
     134    stringto/stringtopointer.c stringto/stringtounsignedint.c \
    134135    stringto/stringtounsignedchar.c stringto/stringtounsignedint.c \
    135136    stringto/stringtounsignedlong.c stringto/stringtounsignedlonglong.c
  • cpukit/libmisc/shell/main_chmod.c

    r73dfaf8 r48751ab  
    4646   *  Convert arguments into numbers
    4747   */
    48   if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     48  if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
    4949    printf( "Mode argument (%s) is not a number\n", argv[1] );
    5050    return -1;
  • cpukit/libmisc/shell/main_mdump.c

    r73dfaf8 r48751ab  
    3232)
    3333{
    34   unsigned long  tmp;
    3534  unsigned char  n;
    3635  unsigned char  m;
    3736  int            max;
    3837  int            res;
    39   uintptr_t      addr = 0;
     38  void          *addr = NULL;
    4039  unsigned char *pb;
    4140
    4241  if (argc > 1) {
    43     if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     42    if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
    4443      printf( "Address argument (%s) is not a number\n", argv[1] );
    4544      return -1;
    4645    }
    47     addr = (uintptr_t) tmp;
    4846
    4947  }
    5048
    51   if (argc>2) {
    52     if ( !rtems_string_to_int(argv[1], &max, NULL, 0) ) {
     49  if (argc > 2) {
     50    if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
    5351      printf( "Length argument (%s) is not a number\n", argv[1] );
    5452      return -1;
    5553    }
    56     addr = (uintptr_t) tmp;
    5754    if (max <= 0) {
    5855      max = 1;      /* print 1 item if 0 or neg. */
    5956      res = 0;
    60     }
    61     else {
     57    } else {
    6258      max--;
    6359      res = max & 0xf;/* num bytes in last row */
     
    6965      }
    7066    }
    71   }
    72   else {
     67  } else {
    7368    max = 20;
    7469    res = 0xf;
    7570  }
    7671
     72  pb = addr;
    7773  for (m=0; m<max; m++) {
    78     pb = (unsigned char*) addr;
    7974    printf("%10p ", pb);
    8075    for (n=0;n<=(m==(max-1)?res:0xf);n++)
     
    8681    }
    8782    printf("\n");
    88     addr += 16;
     83    pb += 16;
    8984  }
    9085  return 0;
  • cpukit/libmisc/shell/main_medit.c

    r73dfaf8 r48751ab  
    3333)
    3434{
    35   unsigned long  tmp;
    3635  unsigned char *pb;
     36  void          *tmpp;
    3737  int            n;
    3838  int            i;
     
    4646   *  Convert arguments into numbers
    4747   */
    48   if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     48  if ( rtems_string_to_pointer(argv[1], &tmpp, NULL) ) {
    4949    printf( "Address argument (%s) is not a number\n", argv[1] );
    5050    return -1;
    5151  }
    52   pb = (unsigned char *) tmp;
     52  pb = tmpp;
    5353
    5454  /*
     
    5959    unsigned char tmpc;
    6060
    61     if ( !rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
     61    if ( rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
    6262      printf( "Value (%s) is not a number\n", argv[i] );
    6363      continue;
  • cpukit/libmisc/shell/main_mfill.c

    r73dfaf8 r48751ab  
    3131)
    3232{
    33   unsigned long tmp;
    34   uintptr_t     addr;
    35   size_t        size;
    36   unsigned char value;
     33  unsigned long  tmp;
     34  void          *addr;
     35  size_t         size;
     36  unsigned char  value;
    3737
    3838  if ( argc != 4 ) {
     
    4444   *  Convert arguments into numbers
    4545   */
    46   if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     46  if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
    4747    printf( "Address argument (%s) is not a number\n", argv[1] );
    4848    return -1;
    4949  }
    50   addr = (uintptr_t) tmp;
    5150
    52   if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     51  if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
    5352    printf( "Size argument (%s) is not a number\n", argv[2] );
    5453    return -1;
     
    5655  size = (size_t) tmp;
    5756
    58   if ( !rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) {
     57  if ( rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) {
    5958    printf( "Value argument (%s) is not a number\n", argv[3] );
    6059    return -1;
     
    6463   *  Now fill the memory.
    6564   */
    66   memset((unsigned char*)addr, size, value);
     65  memset(addr, size, value);
    6766
    6867  return 0;
  • cpukit/libmisc/shell/main_mmove.c

    r73dfaf8 r48751ab  
    3333)
    3434{
    35   unsigned long tmp;
    36   uintptr_t     src;
    37   uintptr_t     dst;
    38   size_t        length;
     35  unsigned long  tmp;
     36  void          *src;
     37  void          *dst;
     38  size_t         length;
    3939
    4040  if ( argc < 4 ) {
     
    4646   *  Convert arguments into numbers
    4747   */
    48   if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     48  if ( rtems_string_to_pointer(argv[1], &dst, NULL) ) {
    4949    printf( "Destination argument (%s) is not a number\n", argv[1] );
    5050    return -1;
    5151  }
    52   dst = (uintptr_t) tmp;
    5352
    54   if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     53  if ( rtems_string_to_pointer(argv[2], &src, NULL) ) {
    5554    printf( "Source argument (%s) is not a number\n", argv[2] );
    5655    return -1;
    5756  }
    58   src = (uintptr_t) tmp;
    5957
    60   if ( !rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) {
     58  if ( rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) {
    6159    printf( "Length argument (%s) is not a number\n", argv[3] );
    6260    return -1;
     
    6765   *  Now copy the memory.
    6866   */
    69   memcpy((unsigned char*)dst, (unsigned char*)src, length);
     67  memcpy(dst, src, length);
    7068
    7169 return 0;
  • cpukit/libmisc/shell/main_msdosfmt.c

    r73dfaf8 r48751ab  
    6565          }
    6666
    67           if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
     67          if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
    6868            printf(
    6969              "sector per cluster argument (%s) is not a number\n",
     
    8383          }
    8484
    85           if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
     85          if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
    8686            printf(
    8787              "root directory size argument (%s) is not a number\n",
  • cpukit/libmisc/shell/main_mwdump.c

    r73dfaf8 r48751ab  
    3232)
    3333{
    34   unsigned long  tmp;
    3534  unsigned char  n;
    3635  unsigned char  m;
    3736  int            max;
    3837  int            res;
    39   uintptr_t      addr = 0;
     38  void          *addr = 0;
    4039  unsigned char *pb;
    4140
    4241  if ( argc > 1 ) {
    43     if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     42    if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
    4443      printf( "Address argument (%s) is not a number\n", argv[1] );
    4544      return -1;
    4645    }
    47     addr = (uintptr_t) tmp;
    4846  }
    4947
    5048  if ( argc > 2 ) {
    51     if ( !rtems_string_to_int(argv[2], &max, NULL, 0) ) {
     49    if ( rtems_string_to_int(argv[2], &max, NULL, 0) ) {
    5250      printf( "Address argument (%s) is not a number\n", argv[1] );
    5351      return -1;
     
    7270  }
    7371
     72  pb = addr;
    7473  for (m=0;m<max;m++) {
    75     pb = (unsigned char *) addr;
    7674    printf("%10p ", pb);
    7775    for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
     
    8381    }
    8482    printf("\n");
    85     addr += 16;
     83    pb += 16;
    8684  }
    8785  return 0;
  • cpukit/libmisc/shell/main_sleep.c

    r73dfaf8 r48751ab  
    4040   *  Convert the seconds argument to a number
    4141   */
    42   if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     42  if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
    4343    printf( "Seconds argument (%s) is not a number\n", argv[1] );
    4444    return -1;
     
    5151  delay.tv_nsec = 0;
    5252  if (argc == 3) {
    53     if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     53    if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
    5454      printf( "Seconds argument (%s) is not a number\n", argv[1] );
    5555      return -1;
  • cpukit/libmisc/shell/main_umask.c

    r73dfaf8 r48751ab  
    3838
    3939  if (argc == 2) {
    40     if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     40    if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
    4141      printf( "Mask argument (%s) is not a number\n", argv[1] );
    4242      return -1;
  • cpukit/libmisc/shell/shell_script.c

    r73dfaf8 r48751ab  
    130130        const char *s = getopt_reent.optarg;
    131131
    132         if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
     132        if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
    133133          printf( "Task Priority argument (%s) is not a number\n", s );
    134134          return -1;
     
    140140        const char *s = getopt_reent.optarg;
    141141
    142         if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
     142        if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
    143143          printf( "Stack size argument (%s) is not a number\n", s );
    144144          return -1;
  • 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.