summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2008-06-02 13:46:35 -0700
committerAaron Plattner <aplattner@nvidia.com>2008-06-02 13:46:35 -0700
commit89e149a1c5f497b6a841e334ccc90755e6a721b4 (patch)
tree70d2814058c08490d6760136f0cffa5eeff08bee
parent57525859c5a1b37d5e8b31f3a924901643687ba0 (diff)
Set the LC_NUMERIC locale to "C" temporarily while parsing modelines.
Modelines from the server always use '.' as the decimal separator, while the LC_NUMERIC locale setting can change it.
-rw-r--r--src/gtk+-2.x/ctkdisplayconfig-utils.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/gtk+-2.x/ctkdisplayconfig-utils.c b/src/gtk+-2.x/ctkdisplayconfig-utils.c
index d99168c..8b41571 100644
--- a/src/gtk+-2.x/ctkdisplayconfig-utils.c
+++ b/src/gtk+-2.x/ctkdisplayconfig-utils.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
+#include <locale.h>
#include <gtk/gtk.h>
@@ -243,7 +244,7 @@ static nvModeLinePtr modeline_parse(const char *modeline_str,
{
nvModeLinePtr modeline = NULL;
const char *str = modeline_str;
- char *tmp;
+ char *tmp, *old_locale;
char *tokens, *nptr;
double pclk, htotal, vtotal, factor;
@@ -252,6 +253,16 @@ static nvModeLinePtr modeline_parse(const char *modeline_str,
modeline = (nvModeLinePtr)calloc(1, sizeof(nvModeLine));
if (!modeline) return NULL;
+ /* Make sure strtod uses . instead of , as the decimal separator */
+ old_locale = setlocale(LC_NUMERIC, NULL);
+
+ if (old_locale)
+ old_locale = strdup(old_locale);
+
+ if (!old_locale || !setlocale(LC_NUMERIC, "C"))
+ nv_warning_msg("Error parsing server modeline '%s': could not "
+ "set the locale 'C'.", modeline_str);
+
/* Parse the modeline tokens */
tmp = strstr(str, "::");
if (tmp) {
@@ -381,12 +392,25 @@ static nvModeLinePtr modeline_parse(const char *modeline_str,
modeline->refresh_rate *= factor;
+ /* Restore the locale */
+ if (old_locale) {
+ setlocale(LC_NUMERIC, old_locale);
+ free(old_locale);
+ }
+
return modeline;
/* Handle failures */
fail:
free(modeline);
+
+ /* Restore the locale */
+ if (old_locale) {
+ setlocale(LC_NUMERIC, old_locale);
+ free(old_locale);
+ }
+
return NULL;
} /* modeline_parse() */