source: rtems/cpukit/libmisc/stringto/stringtofloat.c @ 8b9a33e8

4.115
Last change on this file since 8b9a33e8 was 8b9a33e8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/01/11 at 02:34:19

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

  • libmisc/stringto/stringtodouble.c, libmisc/stringto/stringtofloat.c: Rework.
  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <errno.h>
19#include <stdlib.h>
20#include <math.h>
21
22#include <rtems/stringto.h>
23
24/*
25 *  Instantiate an error checking wrapper for strtof (float)
26 */
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 TracBrowser for help on using the repository browser.