diff --git a/src/configure.in b/src/configure.in index e2e456588237da157cfeb07d6b11bfc75bdf6349..c8c06274f2d23a7c992cdee851c9f9b5d3f2ca2f 100644 --- a/src/configure.in +++ b/src/configure.in @@ -4581,7 +4581,6 @@ AC_CHECK_FUNCS( \ strchr \ strcspn \ strerror \ - strtod \ times \ tzset \ vsprintf \ diff --git a/src/port.c b/src/port.c index ebe1c97e017837e8f177e1c0a12419937763f173..ccb00c911ac210364cbf3850ff2e11525ebb254e 100644 --- a/src/port.c +++ b/src/port.c @@ -341,160 +341,6 @@ PMOD_EXPORT char *STRCHR(char *s,int c) } #endif -#ifndef HAVE_STRTOD -/* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the - character after the last one used in the number is put in *ENDPTR. */ -PMOD_EXPORT double STRTOD(const char * nptr, char **endptr) -{ - /* Note: Code duplication in STRTOD_PCHARP. */ - - register const unsigned char *s; - short int sign; - - /* The number so far. */ - double num; - - int got_dot; /* Found a decimal point. */ - int got_digit; /* Seen any digits. */ - - /* The exponent of the number. */ - long int exponent; - - if (nptr == NULL) - { - errno = EINVAL; - goto noconv; - } - - s = (const unsigned char *)nptr; - - /* Eat whitespace. */ - while (isspace(*s)) ++s; - - /* Get the sign. */ - sign = *s == '-' ? -1 : 1; - if (*s == '-' || *s == '+') - ++s; - - num = 0.0; - got_dot = 0; - got_digit = 0; - exponent = 0; - for (;; ++s) - { - if (isdigit(*s)) - { - got_digit = 1; - - /* Make sure that multiplication by 10 will not overflow. */ - if (num > DBL_MAX * 0.1) - /* The value of the digit doesn't matter, since we have already - gotten as many digits as can be represented in a `double'. - This doesn't necessarily mean the result will overflow. - The exponent may reduce it to within range. - - We just need to record that there was another - digit so that we can multiply by 10 later. */ - ++exponent; - else - num = (num * 10.0) + (*s - '0'); - - /* Keep track of the number of digits after the decimal point. - If we just divided by 10 here, we would lose precision. */ - if (got_dot) - --exponent; - } - else if (!got_dot && (*s == '.')) - /* Record that we have found the decimal point. */ - got_dot = 1; - else - /* Any other character terminates the number. */ - break; - } - - if (!got_digit) - goto noconv; - - if (tolower(*s) == 'e') - { - /* Get the exponent specified after the `e' or `E'. */ - int save = errno; - char *end; - long int exp; - - errno = 0; - ++s; - exp = strtol((const char *)s, &end, 10); - if (errno == ERANGE) - { - /* The exponent overflowed a `long int'. It is probably a safe - assumption that an exponent that cannot be represented by - a `long int' exceeds the limits of a `double'. */ - /* NOTE: Don't trust the value returned from strtol. - * We need to find the sign of the exponent by hand. - */ - while(isspace(*s)) { - s++; - } - if (endptr != NULL) - *endptr = end; - if (*s == '-') - goto underflow; - else - goto overflow; - } - else if (end == (char *)s) - /* There was no exponent. Reset END to point to - the 'e' or 'E', so *ENDPTR will be set there. */ - end = (char *) s - 1; - errno = save; - s = (unsigned char *)end; - exponent += exp; - } - - if (endptr != NULL) - *endptr = (char *) s; - - if (num == 0.0) - return 0.0 * sign; - - /* Multiply NUM by 10 to the EXPONENT power, - checking for overflow and underflow. */ - - if (exponent < 0) - { - if (num < DBL_MIN * pow(10.0, (double) -exponent)) - goto underflow; - - num /= pow(10.0, (double) -exponent); - } - else if (exponent > 0) - { - if (num > DBL_MAX * pow(10.0, (double) -exponent)) - goto overflow; - num *= pow(10.0, (double) exponent); - } - - return num * sign; - - overflow: - /* Return an overflow error. */ - errno = ERANGE; - return HUGE_VAL * sign; - - underflow: - /* Return an underflow error. */ - errno = ERANGE; - return 0.0; - - noconv: - /* There was no number. */ - if (endptr != NULL) - *endptr = (char *) nptr; - return 0.0; -} -#endif - #ifndef HAVE_VSPRINTF PMOD_EXPORT int VSPRINTF(char *buf,const char *fmt,va_list args) { diff --git a/src/port.h b/src/port.h index caf58a7f51928d1e89aaf0b343ea501dfd71d659..29a2156d9e0235f9253f855fe5d273fb06acdcd7 100644 --- a/src/port.h +++ b/src/port.h @@ -152,11 +152,8 @@ void GETTIMEOFDAY(struct timeval *t); #define HAVE_STRTOL 1 #define STRTOL strtol -#ifndef HAVE_STRTOD -PMOD_EXPORT double STRTOD(const char * nptr, char **endptr); -#else -# define STRTOD strtod -#endif +#define HAVE_STRTOD 1 +#define STRTOD strtod #ifndef HAVE_STRCSPN int STRCSPN(const char *s,const char * set); diff --git a/src/stuff.c b/src/stuff.c index 14f00844adc0ee50af0cf67396add18cd8ea2a88..cc63fbb5a59aa0d4728c2b26da1222133f196cc5 100644 --- a/src/stuff.c +++ b/src/stuff.c @@ -132,7 +132,7 @@ PMOD_EXPORT int my_log2(size_t x) PMOD_EXPORT double my_strtod(char *nptr, char **endptr) { - double tmp=STRTOD(nptr,endptr); + double tmp=strtod(nptr,endptr); if(*endptr>nptr) { if(endptr[0][-1]=='.')