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

Submitted by Francois Gouget on Aug. 31, 2015, 1:29 p.m.

Details

Message ID alpine.DEB.2.20.1508311527140.31956@amboise
State New
Headers show

Not browsing as part of any series.

Commit Message

Francois Gouget Aug. 31, 2015, 1:29 p.m.
Issue a warning for invalid values but treat them as TRUE for backward compatibility.

Signed-off-by: Francois Gouget <fgouget@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(-)

Patch hide | download patch | download mbox

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;
 }