From 9a0236b9e249f002accfb222a969be0c676115b7 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Thu, 6 Dec 2012 10:29:23 +0100 Subject: Changed reading and writing of floating point numbers into configuration files to make it independent of the decimal point used in the current locale --- tools.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index efb9f164..8c03c868 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 2.27 2012/12/03 09:31:32 kls Exp $ + * $Id: tools.c 2.28 2012/12/06 09:40:02 kls Exp $ */ #include "tools.h" @@ -18,6 +18,7 @@ extern "C" { #include #undef boolean } +#include #include #include #include @@ -302,6 +303,31 @@ cString AddDirectory(const char *DirName, const char *FileName) return cString::sprintf("%s/%s", DirName && *DirName ? DirName : ".", FileName); } +double atod(const char *s) +{ + static lconv *loc = localeconv(); + char buf[strlen(s) + 1]; + char *p = buf; + while (*s) { + if (*s == '.') + *p = *loc->decimal_point; + else + *p = *s; + p++; + s++; + } + *p = 0; + return atof(buf); +} + +cString dtoa(double d, const char *Format) +{ + static lconv *loc = localeconv(); + char buf[16]; + snprintf(buf, sizeof(buf), Format, d); + return strreplace(buf, *loc->decimal_point, '.'); +} + cString itoa(int n) { char buf[16]; -- cgit v1.2.3