From eb618a0c5c7a3893fc18a8f1e5d39854aa25c597 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 5 Apr 2010 20:37:15 +0200 Subject: plist_to_xml: use POSIX locale to make sure '.' is used for floats In locales like German, a ',' is used as a decimal separator. When the program calling plist_to_xml uses LC_NUMBER with something different than a '.', parsing of the resulting XML document fails. This patch fixes it. --- src/xplist.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/xplist.c b/src/xplist.c index 3e9f043..c7d9cfb 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -371,6 +372,14 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) root_node = xmlDocGetRootElement(plist_doc); root.xml = root_node; + char *current_locale = setlocale(LC_NUMERIC, NULL); + char *saved_locale = NULL; + if (current_locale) { + saved_locale = strdup(current_locale); + } + if (saved_locale) { + setlocale(LC_NUMERIC, "POSIX"); + } node_to_xml(plist, &root); xmlChar* tmp = NULL; @@ -385,6 +394,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) tmp = NULL; } xmlFreeDoc(plist_doc); + + if (saved_locale) { + setlocale(LC_NUMERIC, saved_locale); + free(saved_locale); + } } void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) -- cgit v1.1-32-gdbae