Another round of spelling fixes in manpages, messages, readmes etc.
[dragonfly/vkernel-mp.git] / gnu / usr.bin / sort / xstrtod.c
blob838c5c463213ad4d805db6d36d26c2054eab186c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
5 #ifdef STDC_HEADERS
6 #include <stdlib.h>
7 #else
8 double strtod ();
9 #endif
11 #include <errno.h>
12 #include <stdio.h>
13 #include <limits.h>
14 #include <ctype.h>
15 #include "xstrtod.h"
17 int
18 xstrtod (str, ptr, result)
19 const char *str;
20 const char **ptr;
21 double *result;
23 double val;
24 char *terminator;
25 int fail;
27 fail = 0;
28 errno = 0;
29 val = strtod (str, &terminator);
31 /* Having a non-zero terminator is an error only when PTR is NULL. */
32 if (terminator == str || (ptr == NULL && *terminator != '\0'))
33 fail = 1;
34 else
36 /* Allow underflow (in which case strtod returns zero),
37 but flag overflow as an error. */
38 if (val != 0.0 && errno == ERANGE)
39 fail = 1;
42 if (ptr != NULL)
43 *ptr = terminator;
45 *result = val;
46 return fail;