[Spice-devel] [PATCH v2 1/2] spiceqxl: Recognize the same set of boolean values as in xorg.conf.

Francois Gouget fgouget at codeweavers.com
Mon Aug 31 06:29:29 PDT 2015


Issue a warning for invalid values but treat them as TRUE for backward compatibility.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---

As suggested in:
http://lists.freedesktop.org/archives/spice-devel/2015-August/021392.html

 src/qxl_option_helpers.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/qxl_option_helpers.c b/src/qxl_option_helpers.c
index 8801b53..a42cc84 100644
--- a/src/qxl_option_helpers.c
+++ b/src/qxl_option_helpers.c
@@ -3,6 +3,7 @@
 #endif
 
 #include <stdlib.h>
+#include <strings.h>
 
 #include <xf86.h>
 #include <xf86Opt.h>
@@ -30,12 +31,24 @@ const char *get_str_option(OptionInfoPtr options, int option_index,
 int get_bool_option(OptionInfoPtr options, int option_index,
                      const char *env_name)
 {
-    if (getenv(env_name)) {
-        /* we don't support the whole range of boolean true and
-         * false values documented in man xorg.conf, just the c
-         * convention - 0 is false, anything else is true, so
-         * just like a number. */
-        return !!atoi(getenv(env_name));
+    const char* value = getenv(env_name);
+
+    if (!value) {
+        return options[option_index].value.bool;
+    }
+    if (strcmp(value, "0") == 0 ||
+        strcasecmp(value, "off") == 0 ||
+        strcasecmp(value, "false") == 0 ||
+        strcasecmp(value, "no") == 0) {
+        return FALSE;
     }
-    return options[option_index].value.bool;
+    if (strcmp(value, "1") == 0 ||
+        strcasecmp(value, "on") == 0 ||
+        strcasecmp(value, "true") == 0 ||
+        strcasecmp(value, "yes") == 0) {
+        return TRUE;
+    }
+
+    fprintf(stderr, "spice: treating invalid boolean %s as true: %s\n", env_name, value);
+    return TRUE;
 }
-- 
2.5.0



More information about the Spice-devel mailing list