Changeset 97315f51 in rtems


Ignore:
Timestamp:
Feb 2, 2011, 2:30:10 AM (8 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.10
Children:
b9a1642
Parents:
cc2bcea4
Message:

Backport from CVS-HEAD.

Location:
cpukit
Files:
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rcc2bcea4 r97315f51  
     12011-02-01      Ralf Corsepius <ralf.corsepius@rtems.org>
     2
     3        * libmisc/stringto/stringtounsignedchar.c,
     4        libmisc/stringto/stringtounsignedint.c: Reformat range check.
     5        * libmisc/Makefile.am: Add stringto/stringtolongdouble.c.
     6        * libmisc/stringto/stringtolongdouble.c: New.
     7        * libmisc/stringto/stringto.h: Rename header-guard.
     8        Add rtems_string_to_long_double.
     9        * libmisc/stringto/stringtoint.c: Reformat range check.
     10        Add check for result==0.
     11        * libmisc/stringto/stringtofloat.c: Reformat range check.
     12        Add check for result = -HUGE_VALF.
     13        * libmisc/stringto/stringtodouble.c: Reformat range check.
     14        Add check for result = -HUGE_VAL.
     15        * libmisc/stringto/stringtolonglong.c: Reformat range check.
     16        c99 portability improvements. Add check for result==0.
     17        * libmisc/stringto/stringtounsignedlonglong.c: Reformat range check.
     18        c99 portability improvements.
     19        * libmisc/stringto/stringtounsignedlong.c: Reformat range check.
     20        * libmisc/stringto/stringtolong.c:  Reformat range check.
     21        Add check for result==0.
     22
     232011-02-01      Ralf Corsepius <ralf.corsepius@rtems.org>
     24       
     25        * libmisc/Makefile.am: Remove stringto/stringto_template.h.
     26        * libmisc/stringto/stringto_template.h: Remove.
     27
     28        * libmisc/stringto/stringtodouble.c,
     29        libmisc/stringto/stringtofloat.c: Rework.
     30
     31        * libmisc/stringto/stringtolong.c,
     32        libmisc/stringto/stringtolonglong.c,
     33        libmisc/stringto/stringtounsignedlong.c,
     34        libmisc/stringto/stringtounsignedlonglong.c:
     35        Rework.
     36
    1372011-01-21      Eric Norum <wenorum@lbl.gov>
    238
  • cpukit/libmisc/Makefile.am

    rcc2bcea4 r97315f51  
    136136libstringto_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/stringto
    137137libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \
     138    stringto/stringtolongdouble.c \
    138139    stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \
    139140    stringto/stringtopointer.c stringto/stringtounsignedint.c \
    140141    stringto/stringtounsignedchar.c stringto/stringtounsignedlong.c \
    141     stringto/stringtounsignedlonglong.c stringto/stringto_template.h
     142    stringto/stringtounsignedlonglong.c
    142143
    143144## fsmount
  • cpukit/libmisc/stringto/stringto.h

    rcc2bcea4 r97315f51  
    1010 */
    1111
    12 #ifndef __STRING_TO_A_TYPE_h__
    13 #define __STRING_TO_A_TYPE_h__
     12#ifndef _RTEMS_STRINGTO_H
     13#define _RTEMS_STRINGTO_H
    1414
    1515#include <rtems.h>
     
    225225);
    226226
     227/**
     228 *  @brief Convert String to long double (with validation)
     229 *
     230 *  This method converts a string to a long double with range validation.
     231 *
     232 *  @param[in] s is the string to convert
     233 *  @param[in] n points to the variable to place the converted output in
     234 *  @param[in] endptr is used to keep track of the position in the string
     235 *
     236 *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
     237 *          and *n is filled in.  Otherwise, the status indicates the
     238 *          source of the error.
     239 */
     240rtems_status_code rtems_string_to_long_double(
     241  const char   *s,
     242  long double  *n,
     243  char        **endptr
     244);
     245
    227246#endif
  • cpukit/libmisc/stringto/stringtodouble.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <math.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtod (double)
    1826 */
    19 #define STRING_TO_FLOAT
    20 #define STRING_TO_TYPE double
    21 #define STRING_TO_NAME rtems_string_to_double
    22 #define STRING_TO_METHOD strtod
    23 #define STRING_TO_MAX HUGE_VAL
    24 #include "stringto_template.h"
    2527
     28rtems_status_code rtems_string_to_double (
     29  const char *s,
     30  double *n,
     31  char **endptr
     32)
     33{
     34  double result;
     35  char *end;
     36
     37  if ( !n )
     38    return RTEMS_INVALID_ADDRESS;
     39
     40  errno = 0;
     41  *n = 0;
     42
     43  result = strtod( s, &end );
     44
     45  if ( endptr )
     46    *endptr = end;
     47
     48  if ( end == s )
     49    return RTEMS_NOT_DEFINED;
     50
     51  if ( ( errno == ERANGE ) &&
     52    (( result == 0 ) || ( result == HUGE_VAL ) || ( result == -HUGE_VAL )))
     53      return RTEMS_INVALID_NUMBER;
     54
     55  *n = result;
     56
     57  return RTEMS_SUCCESSFUL;
     58}
  • cpukit/libmisc/stringto/stringtofloat.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <math.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtof (float)
    1826 */
    19 #define STRING_TO_FLOAT
    20 #define STRING_TO_TYPE float
    21 #define STRING_TO_NAME rtems_string_to_float
    22 #define STRING_TO_METHOD strtof
    23 #define STRING_TO_MAX HUGE_VALF
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_float (
     29  const char *s,
     30  float *n,
     31  char **endptr
     32)
     33{
     34  float result;
     35  char *end;
     36
     37  if ( !n )
     38    return RTEMS_INVALID_ADDRESS;
     39
     40  errno = 0;
     41  *n = 0;
     42
     43  result = strtof( s, &end );
     44
     45  if ( endptr )
     46    *endptr = end;
     47
     48  if ( end == s )
     49    return RTEMS_NOT_DEFINED;
     50
     51  if ( ( errno == ERANGE ) &&
     52    (( result == 0 ) || ( result == HUGE_VALF ) || ( result == -HUGE_VALF )))
     53      return RTEMS_INVALID_NUMBER;
     54
     55  *n = result;
     56
     57  return RTEMS_SUCCESSFUL;
     58}
  • cpukit/libmisc/stringto/stringtoint.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtol (int)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE int
    21 #define STRING_TO_NAME rtems_string_to_int
    22 #define STRING_TO_METHOD strtol
    23 #define STRING_TO_MAX LONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_int (
     29  const char *s,
     30  int *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtol( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( ( errno == ERANGE ) &&
     53    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
     54      return RTEMS_INVALID_NUMBER;
     55
     56#if (INT_MAX < LONG_MAX)
     57  if ( result > INT_MAX ) {
     58    errno = ERANGE;
     59    return RTEMS_INVALID_NUMBER;
     60  }
     61#endif
     62
     63#if (INT_MIN < LONG_MIN)
     64  if ( result < INT_MIN ) {
     65    errno = ERANGE;
     66    return RTEMS_INVALID_NUMBER;
     67  }
     68#endif
     69
     70  *n = result;
     71
     72  return RTEMS_SUCCESSFUL;
     73}
  • cpukit/libmisc/stringto/stringtolong.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtol (long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE long int
    21 #define STRING_TO_NAME rtems_string_to_long
    22 #define STRING_TO_METHOD strtol
    23 #define STRING_TO_MIN LONG_MIN
    24 #define STRING_TO_MAX LONG_MAX
    25 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_long (
     29  const char *s,
     30  long *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtol( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( ( errno == ERANGE ) &&
     53    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
     54      return RTEMS_INVALID_NUMBER;
     55
     56  *n = result;
     57
     58  return RTEMS_SUCCESSFUL;
     59}
  • cpukit/libmisc/stringto/stringtolonglong.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
     24/* c99 has LLONG_MAX instead of LONG_LONG_MAX */
     25#ifndef LONG_LONG_MAX
     26#define LONG_LONG_MAX   LLONG_MAX
     27#endif
     28/* c99 has LLONG_MIN instead of LONG_LONG_MIN */
     29#ifndef LONG_LONG_MIN
     30#define LONG_LONG_MIN   LLONG_MIN
     31#endif
     32
    1633/*
    1734 *  Instantiate an error checking wrapper for strtoll (long long)
    1835 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE long long
    21 #define STRING_TO_NAME rtems_string_to_long_long
    22 #define STRING_TO_METHOD strtoll
    23 #define STRING_TO_MIN LONG_LONG_MIN
    24 #define STRING_TO_MAX LONG_LONG_MAX
    25 #include "stringto_template.h"
     36
     37rtems_status_code rtems_string_to_long_long (
     38  const char *s,
     39  long long *n,
     40  char **endptr,
     41  int base
     42)
     43{
     44  long long result;
     45  char *end;
     46
     47  if ( !n )
     48    return RTEMS_INVALID_ADDRESS;
     49
     50  errno = 0;
     51  *n = 0;
     52
     53  result = strtoll( s, &end, base );
     54
     55  if ( endptr )
     56    *endptr = end;
     57
     58  if ( end == s )
     59    return RTEMS_NOT_DEFINED;
     60
     61  if ( ( errno == ERANGE ) &&
     62    (( result == 0 ) || ( result == LONG_LONG_MAX ) || ( result == LONG_LONG_MIN )))
     63      return RTEMS_INVALID_NUMBER;
     64
     65  *n = result;
     66
     67  return RTEMS_SUCCESSFUL;
     68}
  • cpukit/libmisc/stringto/stringtopointer.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21#include <stdint.h>
     22
     23#include <rtems/stringto.h>
     24
    1625/*
    17  *  Instantiate an error checking wrapper for strtoul which is
    18  *  used to input a (void *)
    19  *
    20  *  NOTE: This is only an appropriate implementation when unsigned long
    21  *        can represent a void *
     26 *  Instantiate an error checking wrapper for strtoul/strtoull (void *)
    2227 */
    23 #define STRING_TO_POINTER
    24 #define STRING_TO_TYPE void *
    25 #define STRING_TO_INPUT_TYPE unsigned long
    26 #define STRING_TO_NAME rtems_string_to_pointer
    27 #define STRING_TO_METHOD strtoul
    28 #define STRING_TO_MAX ULONG_MAX
    29 #include "stringto_template.h"
     28
     29#if (UINTPTR_MAX == ULONG_MAX)
     30#define STRTOFUNC(a,b,c)        rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
     31#elif (UINTPTR_MAX == ULONG_LONG_MAX)
     32#define STRTOFUNC(a,b,c)        rtems_string_to_unsigned_long_long(a, (unsigned long long*) b, c, 0)
     33#elif (UINTPTR_MAX == UINT_MAX)
     34#define STRTOFUNC(a,b,c)        rtems_string_to_unsigned_int(a, (unsigned int*) b, c, 0)
     35#else
     36/* Fallback to unsigned long */
     37#define STRTOFUNC(a,b,c)        rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
     38#endif
     39
     40rtems_status_code rtems_string_to_pointer (
     41  const char *s,
     42  void **n,
     43  char **endptr
     44)
     45{
     46  return STRTOFUNC( s, n, endptr );
     47}
  • cpukit/libmisc/stringto/stringtounsignedchar.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    17  *  Instantiate an error checking wrapper for strtol (unsigned char)
     25 *  Instantiate an error checking wrapper for strtoul (unsigned char)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned char
    21 #define STRING_TO_NAME rtems_string_to_unsigned_char
    22 #define STRING_TO_METHOD strtoul
    23 #define STRING_TO_MAX ULONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_char (
     29  const char *s,
     30  unsigned char *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoul( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( ( errno == ERANGE ) &&
     53    (( result == 0 ) || ( result == ULONG_MAX )))
     54      return RTEMS_INVALID_NUMBER;
     55
     56#if (UCHAR_MAX < ULONG_MAX)
     57  if ( result > UCHAR_MAX ) {
     58    errno = ERANGE;
     59    return RTEMS_INVALID_NUMBER;
     60  }
     61#endif
     62
     63  *n = result;
     64
     65  return RTEMS_SUCCESSFUL;
     66}
  • cpukit/libmisc/stringto/stringtounsignedint.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtoul (unsigned int)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned int
    21 #define STRING_TO_NAME rtems_string_to_unsigned_int
    22 #define STRING_TO_METHOD strtoul
    23 #define STRING_TO_MAX ULONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_int (
     29  const char *s,
     30  unsigned int *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoul( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( ( errno == ERANGE ) &&
     53    (( result == 0 ) || ( result == ULONG_MAX )))
     54      return RTEMS_INVALID_NUMBER;
     55
     56#if (UINT_MAX < ULONG_MAX)
     57  if ( result > UINT_MAX ) {
     58    errno = ERANGE;
     59    return RTEMS_INVALID_NUMBER;
     60  }
     61#endif
     62
     63  *n = result;
     64
     65  return RTEMS_SUCCESSFUL;
     66}
  • cpukit/libmisc/stringto/stringtounsignedlong.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtoul (unsigned long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned long int
    21 #define STRING_TO_NAME rtems_string_to_unsigned_long
    22 #define STRING_TO_METHOD strtoul
    23 #define STRING_TO_MAX ULONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_long (
     29  const char *s,
     30  unsigned long *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoul( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( ( errno == ERANGE ) &&
     53    (( result == 0 ) || ( result == ULONG_MAX )))
     54      return RTEMS_INVALID_NUMBER;
     55
     56  *n = result;
     57
     58  return RTEMS_SUCCESSFUL;
     59}
  • cpukit/libmisc/stringto/stringtounsignedlonglong.c

    rcc2bcea4 r97315f51  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
     24/* c99 has ULLONG_MAX instead of ULONG_LONG_MAX */
     25#ifndef ULONG_LONG_MAX
     26#define ULONG_LONG_MAX  ULLONG_MAX
     27#endif
     28
    1629/*
    1730 *  Instantiate an error checking wrapper for strtoull (unsigned long long)
    1831 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned long long
    21 #define STRING_TO_NAME rtems_string_to_unsigned_long_long
    22 #define STRING_TO_METHOD strtoull
    23 #define STRING_TO_MAX ULONG_LONG_MAX
    24 #include "stringto_template.h"
     32
     33rtems_status_code rtems_string_to_unsigned_long_long (
     34  const char *s,
     35  unsigned long long *n,
     36  char **endptr,
     37  int base
     38)
     39{
     40  unsigned long long result;
     41  char *end;
     42
     43  if ( !n )
     44    return RTEMS_INVALID_ADDRESS;
     45
     46  errno = 0;
     47  *n = 0;
     48
     49  result = strtoull( s, &end, base );
     50
     51  if ( endptr )
     52    *endptr = end;
     53
     54  if ( end == s )
     55    return RTEMS_NOT_DEFINED;
     56
     57  if ( ( errno == ERANGE ) &&
     58    (( result == 0 ) || ( result == ULONG_LONG_MAX )))
     59      return RTEMS_INVALID_NUMBER;
     60
     61  *n = result;
     62
     63  return RTEMS_SUCCESSFUL;
     64}
Note: See TracChangeset for help on using the changeset viewer.