diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2012-12-06 10:29:23 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2012-12-06 10:29:23 +0100 |
commit | 9a0236b9e249f002accfb222a969be0c676115b7 (patch) | |
tree | 716651c5a29f20266b8074fb8301ce2be9f93c98 /tools.c | |
parent | c005465d9005c7b8918564055639c1766c099121 (diff) | |
download | vdr-9a0236b9e249f002accfb222a969be0c676115b7.tar.gz vdr-9a0236b9e249f002accfb222a969be0c676115b7.tar.bz2 |
Changed reading and writing of floating point numbers into configuration files to make it independent of the decimal point used in the current locale
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -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 <jpeglib.h> #undef boolean } +#include <locale.h> #include <stdlib.h> #include <sys/time.h> #include <sys/vfs.h> @@ -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]; |