source: rtems/cpukit/libmisc/stringto/stringtofloat.c

5
Last change on this file was cfe8f7a, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 27, 2020 at 2:14:06 PM

doxygen: Switch @brief and @ingroup

This order change fixes the Latex documentation build via Doxygen.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup libmisc_conv_help Conversion Helpers
5 *
6 * @brief Convert String to Float (with validation)
7 */
8
9/*
10 *  COPYRIGHT (c) 2009.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <errno.h>
25#include <stdlib.h>
26#include <math.h>
27
28#include <rtems/stringto.h>
29
30/*
31 *  Instantiate an error checking wrapper for strtof (float)
32 */
33
34rtems_status_code rtems_string_to_float (
35  const char *s,
36  float *n,
37  char **endptr
38)
39{
40  float result;
41  char *end;
42
43  if ( !n )
44    return RTEMS_INVALID_ADDRESS;
45
46  errno = 0;
47  *n = 0;
48
49  result = strtof( s, &end );
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 == HUGE_VALF ) || ( result == -HUGE_VALF )))
59      return RTEMS_INVALID_NUMBER;
60
61  *n = result;
62
63  return RTEMS_SUCCESSFUL;
64}
Note: See TracBrowser for help on using the repository browser.