X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fstrtod.c;h=7bb11d286a5ae8442175906c9147e92af9b969c4;hb=bb1183e25ae74ba21500fb4e39bc1ca9822e3086;hp=c86c73de9b3870c5a4d40dc7aa5e663ca4870740;hpb=ed288bb597072176e84fc8279707a3f2f475779b;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/strtod.c b/libiberty/strtod.c index c86c73de9b..7bb11d286a 100644 --- a/libiberty/strtod.c +++ b/libiberty/strtod.c @@ -1,5 +1,5 @@ /* Implementation of strtod for systems with atof. - Copyright (C) 1991, 1995 Free Software Foundation, Inc. + Copyright (C) 1991-2019 Free Software Foundation, Inc. This file is part of the libiberty library. This library is free software; you can redistribute it and/or modify it under the @@ -14,7 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause @@ -22,18 +22,33 @@ the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ -#include +/* -extern double atof (); +@deftypefn Supplemental double strtod (const char *@var{string}, @ + char **@var{endptr}) + +This ISO C function converts the initial portion of @var{string} to a +@code{double}. If @var{endptr} is not @code{NULL}, a pointer to the +character after the last character used in the conversion is stored in +the location referenced by @var{endptr}. If no conversion is +performed, zero is returned and the value of @var{string} is stored in +the location referenced by @var{endptr}. + +@end deftypefn + +*/ + +#include "ansidecl.h" +#include "safe-ctype.h" + +extern double atof (const char *); /* Disclaimer: this is currently just used by CHILL in GDB and therefore has not been tested well. It may have been tested for nothing except that it compiles. */ double -strtod (str, ptr) - char *str; - char **ptr; +strtod (char *str, char **ptr) { char *p; @@ -42,7 +57,7 @@ strtod (str, ptr) p = str; - while (isspace (*p)) + while (ISSPACE (*p)) ++p; if (*p == '+' || *p == '-') @@ -59,7 +74,7 @@ strtod (str, ptr) && (p[6] == 't' || p[6] == 'T') && (p[7] == 'y' || p[7] == 'Y')) { - *ptr = p + 7; + *ptr = p + 8; return atof (str); } else @@ -88,10 +103,10 @@ strtod (str, ptr) } /* digits, with 0 or 1 periods in it. */ - if (isdigit (*p) || *p == '.') + if (ISDIGIT (*p) || *p == '.') { int got_dot = 0; - while (isdigit (*p) || (!got_dot && *p == '.')) + while (ISDIGIT (*p) || (!got_dot && *p == '.')) { if (*p == '.') got_dot = 1; @@ -105,9 +120,9 @@ strtod (str, ptr) i = 1; if (p[i] == '+' || p[i] == '-') ++i; - if (isdigit (p[i])) + if (ISDIGIT (p[i])) { - while (isdigit (p[i])) + while (ISDIGIT (p[i])) ++i; *ptr = p + i; return atof (str);