summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Čihař <mcihar@suse.cz>2012-02-09 10:12:54 +0100
committerMichal Čihař <mcihar@suse.cz>2012-02-09 10:16:45 +0100
commit69c9181547946cc8618c8c399c1c2253bf640b29 (patch)
treee7c24d8e25e5f3b488377258967075cdc1dcedb1
parent4437dcc83c90f775d2ddb600de3f020b7a6b363d (diff)
downloadlcms2-69c9181547946cc8618c8c399c1c2253bf640b29.tar.gz
Make float parsing work in different locales
Directly using atof is wrong as it is locale dependent and in some languyages decimals separator is not . as is used in CCMX. This leads to failure (or rather to trimming decimal part of the numbers). This change uses printf to figure out what current locale use, localeconv might sound as better to use, but it's definitely not thread safe so it sounds like potential source of troubles.
-rw-r--r--src/cmscgats.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cmscgats.c b/src/cmscgats.c
index 378392c..433c39e 100644
--- a/src/cmscgats.c
+++ b/src/cmscgats.c
@@ -43,6 +43,7 @@
#else
# define DIR_CHAR '/'
#endif
+#include <stdio.h>
// Symbols
typedef enum {
@@ -406,11 +407,29 @@ cmsBool isabsolutepath(const char *path)
}
// Parses float number
+// This can not call directly atof because it uses locale dependant
+// parsing, while CCMX files always use . as decimal separator
static
cmsFloat64Number ParseFloatNumber(const char *Buffer)
{
+ char *tmp, *pos, number[10];
+ cmsFloat64Number ret;
+
if (Buffer) {
- return atof(Buffer);
+ // Try to detect which decimal separator current locale uses
+ sprintf(number, "%f", 0.5);
+ // Is locale specific comma different?
+ if (number[1] == '.') {
+ return atof(Buffer);
+ } else {
+ tmp = strdup(Buffer);
+ while ((pos = strchr(tmp, '.')) != NULL) {
+ *pos = number[1];
+ }
+ ret = atof(tmp);
+ free(tmp);
+ return ret;
+ }
} else {
return 0.0;
}