4.115
Last change
on this file since 61bbacea was
61bbacea,
checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/01/11 at 05:41:07
|
2011-02-01 Ralf Corsepius <ralf.corsepius@…>
- libmisc/stringto/stringtodouble.c: Reformat range check.
Add check for result = -HUGE_VAL.
|
-
Property mode set to
100644
|
File size:
1022 bytes
|
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 strtod (double) |
---|
26 | */ |
---|
27 | |
---|
28 | rtems_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 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.