summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorCristian Rodríguez <crrodriguez@opensuse.org>2015-01-15 02:27:34 -0300
committerDavid Herrmann <dh.herrmann@gmail.com>2015-01-18 22:08:44 +0100
commit0193ad26ba121f3df259cc8b3bab54a99b8e5252 (patch)
treeb30bd4d5785661534b0db293c7e7ef89f0b4635b /src/shared/util.c
parent43fcd650e5cb0836cfc9f667ed74b3bc0283a81c (diff)
util: replace RUN_WITH_LOCALE with extended locale functions
There were two callers, one can use strtod_l() and the other strptime_l(). (David: fix up commit-msg and coding-style)
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 884e782c4f..8f6d5e660c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -507,18 +507,24 @@ int safe_atolli(const char *s, long long int *ret_lli) {
int safe_atod(const char *s, double *ret_d) {
char *x = NULL;
double d = 0;
+ locale_t loc;
assert(s);
assert(ret_d);
- RUN_WITH_LOCALE(LC_NUMERIC_MASK, "C") {
- errno = 0;
- d = strtod(s, &x);
- }
+ loc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
+ if (loc == (locale_t) 0)
+ return -errno;
- if (!x || x == s || *x || errno)
+ errno = 0;
+ d = strtod_l(s, &x, loc);
+
+ if (!x || x == s || *x || errno) {
+ freelocale(loc);
return errno ? -errno : -EINVAL;
+ }
+ freelocale(loc);
*ret_d = (double) d;
return 0;
}