Commit eb618a0c authored by Nikias Bassen's avatar Nikias Bassen Committed by Jonathan Beck

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.
parent 774ce250
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <locale.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
...@@ -371,6 +372,14 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) ...@@ -371,6 +372,14 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
root_node = xmlDocGetRootElement(plist_doc); root_node = xmlDocGetRootElement(plist_doc);
root.xml = root_node; 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); node_to_xml(plist, &root);
xmlChar* tmp = NULL; xmlChar* tmp = NULL;
...@@ -385,6 +394,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) ...@@ -385,6 +394,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
tmp = NULL; tmp = NULL;
} }
xmlFreeDoc(plist_doc); 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) void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment