Changeset 8b9a33e8 in rtems


Ignore:
Timestamp:
Feb 1, 2011, 2:34:19 AM (8 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.11, master
Children:
58a9213d
Parents:
2f8f4950
Message:

2011-02-01 Ralf Corsepius <ralf.corsepius@…>

  • libmisc/stringto/stringtodouble.c, libmisc/stringto/stringtofloat.c: Rework.
Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r2f8f4950 r8b9a33e8  
    112011-02-01      Ralf Corsepius <ralf.corsepius@rtems.org>
     2
     3        * libmisc/stringto/stringtodouble.c,
     4        libmisc/stringto/stringtofloat.c: Rework.
    25
    36        * libmisc/stringto/stringtolong.c,
  • cpukit/libmisc/stringto/stringtodouble.c

    r2f8f4950 r8b9a33e8  
    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 ( (result == HUGE_VAL) && (errno == ERANGE))
     52      return RTEMS_INVALID_NUMBER;
     53  if ( (result == 0) && (errno == ERANGE))
     54      return RTEMS_INVALID_NUMBER;
     55
     56  *n = result;
     57
     58  return RTEMS_SUCCESSFUL;
     59}
  • cpukit/libmisc/stringto/stringtofloat.c

    r2f8f4950 r8b9a33e8  
    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 ( (result == HUGE_VALF) && (errno == ERANGE))
     52      return RTEMS_INVALID_NUMBER;
     53  if ( (result == 0) && (errno == ERANGE))
     54      return RTEMS_INVALID_NUMBER;
     55
     56  *n = result;
     57
     58  return RTEMS_SUCCESSFUL;
     59}
Note: See TracChangeset for help on using the changeset viewer.