diff options
-rw-r--r-- | THANKS.in | 1 | ||||
-rw-r--r-- | lib/c-strtod.c | 81 | ||||
-rw-r--r-- | lib/c-strtod.h | 2 | ||||
-rw-r--r-- | lib/c-strtold.c | 2 | ||||
-rw-r--r-- | m4/c-strtod.m4 | 55 | ||||
-rw-r--r-- | m4/np_coreutils.m4 | 1 | ||||
-rw-r--r-- | plugins/Makefile.am | 4 |
7 files changed, 145 insertions, 1 deletions
@@ -184,3 +184,4 @@ Jason Kau | |||
184 | Michael Tiernan | 184 | Michael Tiernan |
185 | Jeremy Reed | 185 | Jeremy Reed |
186 | Holger Weiss | 186 | Holger Weiss |
187 | Cire Iriarte | ||
diff --git a/lib/c-strtod.c b/lib/c-strtod.c new file mode 100644 index 0000000..031f5f8 --- /dev/null +++ b/lib/c-strtod.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* Convert string to double, using the C locale. | ||
2 | |||
3 | Copyright (C) 2003, 2004 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | #ifdef HAVE_CONFIG_H | ||
22 | # include <config.h> | ||
23 | #endif | ||
24 | |||
25 | #include "c-strtod.h" | ||
26 | |||
27 | #include <locale.h> | ||
28 | #include <stdlib.h> | ||
29 | |||
30 | #include "xalloc.h" | ||
31 | |||
32 | #if LONG | ||
33 | # define C_STRTOD c_strtold | ||
34 | # define DOUBLE long double | ||
35 | # define STRTOD_L strtold_l | ||
36 | #else | ||
37 | # define C_STRTOD c_strtod | ||
38 | # define DOUBLE double | ||
39 | # define STRTOD_L strtod_l | ||
40 | #endif | ||
41 | |||
42 | /* c_strtold falls back on strtod if strtold doesn't conform to C99. */ | ||
43 | #if LONG && HAVE_C99_STRTOLD | ||
44 | # define STRTOD strtold | ||
45 | #else | ||
46 | # define STRTOD strtod | ||
47 | #endif | ||
48 | |||
49 | DOUBLE | ||
50 | C_STRTOD (char const *nptr, char **endptr) | ||
51 | { | ||
52 | DOUBLE r; | ||
53 | |||
54 | #ifdef LC_ALL_MASK | ||
55 | |||
56 | locale_t c_locale = newlocale (LC_ALL_MASK, "C", 0); | ||
57 | r = STRTOD_L (nptr, endptr, c_locale); | ||
58 | freelocale (c_locale); | ||
59 | |||
60 | #else | ||
61 | |||
62 | char *saved_locale = setlocale (LC_NUMERIC, NULL); | ||
63 | |||
64 | if (saved_locale) | ||
65 | { | ||
66 | saved_locale = xstrdup (saved_locale); | ||
67 | setlocale (LC_NUMERIC, "C"); | ||
68 | } | ||
69 | |||
70 | r = STRTOD (nptr, endptr); | ||
71 | |||
72 | if (saved_locale) | ||
73 | { | ||
74 | setlocale (LC_NUMERIC, saved_locale); | ||
75 | free (saved_locale); | ||
76 | } | ||
77 | |||
78 | #endif | ||
79 | |||
80 | return r; | ||
81 | } | ||
diff --git a/lib/c-strtod.h b/lib/c-strtod.h new file mode 100644 index 0000000..ca9a9e7 --- /dev/null +++ b/lib/c-strtod.h | |||
@@ -0,0 +1,2 @@ | |||
1 | double c_strtod (char const *, char **); | ||
2 | long double c_strtold (char const *, char **); | ||
diff --git a/lib/c-strtold.c b/lib/c-strtold.c new file mode 100644 index 0000000..5510e4a --- /dev/null +++ b/lib/c-strtold.c | |||
@@ -0,0 +1,2 @@ | |||
1 | #define LONG 1 | ||
2 | #include "c-strtod.c" | ||
diff --git a/m4/c-strtod.m4 b/m4/c-strtod.m4 new file mode 100644 index 0000000..ffeb458 --- /dev/null +++ b/m4/c-strtod.m4 | |||
@@ -0,0 +1,55 @@ | |||
1 | # c-strtod.m4 serial 6 | ||
2 | |||
3 | # Copyright (C) 2004, 2005 Free Software Foundation, Inc. | ||
4 | # This file is free software; the Free Software Foundation | ||
5 | # gives unlimited permission to copy and/or distribute it, | ||
6 | # with or without modifications, as long as this notice is preserved. | ||
7 | |||
8 | # Written by Paul Eggert. | ||
9 | |||
10 | AC_DEFUN([gl_C99_STRTOLD], | ||
11 | [ | ||
12 | AC_CACHE_CHECK([whether strtold conforms to C99], | ||
13 | [gl_cv_func_c99_strtold], | ||
14 | [AC_COMPILE_IFELSE( | ||
15 | [AC_LANG_PROGRAM( | ||
16 | [[/* On HP-UX before 11.23, strtold returns a struct instead of | ||
17 | long double. Reject implementations like that, by requiring | ||
18 | compatibility with the C99 prototype. */ | ||
19 | #include <stdlib.h> | ||
20 | static long double (*p) (char const *, char **) = strtold; | ||
21 | static long double | ||
22 | test (char const *nptr, char **endptr) | ||
23 | { | ||
24 | long double r; | ||
25 | r = strtold (nptr, endptr); | ||
26 | return r; | ||
27 | }]], | ||
28 | [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])], | ||
29 | [gl_cv_func_c99_strtold=yes], | ||
30 | [gl_cv_func_c99_strtold=no])]) | ||
31 | if test $gl_cv_func_c99_strtold = yes; then | ||
32 | AC_DEFINE([HAVE_C99_STRTOLD], 1, [Define to 1 if strtold conforms to C99.]) | ||
33 | fi | ||
34 | ]) | ||
35 | |||
36 | AC_DEFUN([gl_C_STRTOD], | ||
37 | [ | ||
38 | AC_LIBSOURCES([c-strtod.c, c-strtod.h]) | ||
39 | AC_LIBOBJ([c-strtod]) | ||
40 | |||
41 | dnl Prerequisites of lib/c-strtod.c. | ||
42 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
43 | : | ||
44 | ]) | ||
45 | |||
46 | AC_DEFUN([gl_C_STRTOLD], | ||
47 | [ | ||
48 | AC_LIBSOURCES([c-strtold.c, c-strtod.h]) | ||
49 | AC_LIBOBJ([c-strtold]) | ||
50 | |||
51 | dnl Prerequisites of lib/c-strtold.c. | ||
52 | AC_REQUIRE([gl_C_STRTOD]) | ||
53 | AC_REQUIRE([gl_C99_STRTOLD]) | ||
54 | : | ||
55 | ]) | ||
diff --git a/m4/np_coreutils.m4 b/m4/np_coreutils.m4 index 44aa3b8..18c5f66 100644 --- a/m4/np_coreutils.m4 +++ b/m4/np_coreutils.m4 | |||
@@ -11,6 +11,7 @@ dnl Usually in coreutils' prereq.m4, but this is a subset that we need | |||
11 | AC_DEFUN([np_COREUTILS], | 11 | AC_DEFUN([np_COREUTILS], |
12 | [ | 12 | [ |
13 | AC_REQUIRE([AM_STDBOOL_H]) | 13 | AC_REQUIRE([AM_STDBOOL_H]) |
14 | AC_REQUIRE([gl_C_STRTOLD]) | ||
14 | AC_REQUIRE([gl_GETOPT]) | 15 | AC_REQUIRE([gl_GETOPT]) |
15 | AC_REQUIRE([gl_AFS]) | 16 | AC_REQUIRE([gl_AFS]) |
16 | AC_REQUIRE([gl_EXITFAIL]) | 17 | AC_REQUIRE([gl_EXITFAIL]) |
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 183f4f1..81645b8 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -11,7 +11,9 @@ localedir = $(datadir)/locale | |||
11 | DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ | 11 | DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ |
12 | LIBS = @LIBINTL@ @LIBS@ @SSLLIBS@ | 12 | LIBS = @LIBINTL@ @LIBS@ @SSLLIBS@ |
13 | MATHLIBS = @MATHLIBS@ | 13 | MATHLIBS = @MATHLIBS@ |
14 | AM_CFLAGS = -Wall | 14 | |
15 | # This is not portable. Run ". tools/devmode" to get development compile flags | ||
16 | #AM_CFLAGS = -Wall | ||
15 | 17 | ||
16 | libexec_PROGRAMS = check_apt check_disk check_dummy check_http check_load \ | 18 | libexec_PROGRAMS = check_apt check_disk check_dummy check_http check_load \ |
17 | check_mrtg check_mrtgtraf check_ntp check_nwstat check_overcr check_ping \ | 19 | check_mrtg check_mrtgtraf check_ntp check_nwstat check_overcr check_ping \ |