summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-11-27 07:48:21 +0000
committerJim Meyering <jim@meyering.net>2003-11-27 07:48:21 +0000
commitc0f0a326af784572b7894d01dc69bdd29211db8a (patch)
treeb1314d637f0672c10a31779bf9bb1d39f58783cc
parent05c5b74a058780b6ac79a60e1b06e182f3b877e4 (diff)
downloadcoreutils-c0f0a326af784572b7894d01dc69bdd29211db8a.tar.xz
(xstrtod): Accept an extra arg, specifying the conversion function.
Don't include stdlib.h; no longer needed.
-rw-r--r--lib/xstrtod.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/xstrtod.c b/lib/xstrtod.c
index 8450829bd..1a0b4d460 100644
--- a/lib/xstrtod.c
+++ b/lib/xstrtod.c
@@ -1,4 +1,4 @@
-/* xstrtod.c - error-checking interface to strtod
+/* error-checking interface to strtod-like functions
Copyright (C) 1996, 1999, 2000, 2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,6 @@
#include <errno.h>
#include <limits.h>
#include <stdio.h>
-#include <stdlib.h>
/* Tell the compiler that non-default rounding modes are used. */
#if 199901 <= __STDC_VERSION__
@@ -36,10 +35,12 @@
/* An interface to strtod that encapsulates all the error checking
one should usually perform. Like strtod, but upon successful
conversion put the result in *RESULT and return zero. Return
- non-zero and don't modify *RESULT upon any failure. */
+ non-zero and don't modify *RESULT upon any failure. CONVERT
+ specifies the conversion function, e.g., strtod itself. */
int
-xstrtod (char const *str, char const **ptr, double *result)
+xstrtod (char const *str, char const **ptr, double *result,
+ double (*convert) (char const *, char **))
{
double val;
char *terminator;
@@ -47,7 +48,7 @@ xstrtod (char const *str, char const **ptr, double *result)
fail = 0;
errno = 0;
- val = strtod (str, &terminator);
+ val = convert (str, &terminator);
/* Having a non-zero terminator is an error only when PTR is NULL. */
if (terminator == str || (ptr == NULL && *terminator != '\0'))