[libgudev/wip/hadess/uncached-bools: 1/3] gudev: Add support for Y/N, y/n as bool sysfs attributes




commit e186dac0c69edbb53b1456a25cb076e20eb576d6
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Mar 16 10:54:05 2021 +0100

    gudev: Add support for Y/N, y/n as bool sysfs attributes
    
    Which matches the string representation of a "bool" as used in module
    parameters:
    "
    Standard types are:
    [...]
     *  bool: a bool, values 0/1, y/n, Y/N.
    "
    
    See 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/moduleparam.h#n123

 gudev/gudevdevice.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gudev/gudevdevice.c b/gudev/gudevdevice.c
index df6ebd1..e14f367 100644
--- a/gudev/gudevdevice.c
+++ b/gudev/gudevdevice.c
@@ -613,7 +613,7 @@ out:
  *
  * Look up the value for @key on @device and convert it to an
  * boolean. This is done by doing a case-insensitive string comparison
- * on the string value against "1" and "true".
+ * on the string value against "1", "true", "Y" and "y".
  *
  * Returns: The value for @key or %FALSE if @key doesn't exist or
  * isn't a #gboolean.
@@ -926,8 +926,12 @@ g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice  *device,
   if (s == NULL)
     goto out;
 
-  if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
+  if (strcmp (s, "1") == 0 ||
+      g_ascii_strcasecmp (s, "true") == 0 ||
+      g_ascii_strcasecmp (s, "y") == 0) {
     result = TRUE;
+  }
+
  out:
   return result;
 }
@@ -1141,7 +1145,7 @@ out:
  *
  * Look up the sysfs attribute with @name on @device and convert it to an
  * boolean. This is done by doing a case-insensitive string comparison
- * on the string value against "1" and "true". This function does
+ * on the string value against "1", "true", "Y" and "y". This function does
  * blocking I/O, and updates the sysfs attributes cache.
  *
  * Returns: The value of the sysfs attribute or %FALSE if there is no such


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]