]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
libply: Add ply_key_file_get_double() function
authorHans de Goede <hdegoede@redhat.com>
Wed, 25 Sep 2019 19:30:44 +0000 (21:30 +0200)
committerHans de Goede <hdegoede@redhat.com>
Wed, 25 Sep 2019 19:33:52 +0000 (21:33 +0200)
Add a ply_key_file_get_double() function which plugins can use to read
a double value, instead of them having to repeat this pattern over and over:

  double_str = ply_key_file_get_value (key_file, "group", "key");
  if (double_str != NULL)
      foo = ply_strtod (double_str);
  else
      foo = 1.0;
  free (double_str);

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/libply/ply-key-file.c
src/libply/ply-key-file.h

index 7d9b7ab2ed2de917bac94bf84fa35dfb5a494a21..e31f39a3c2eefa5ef4d51a250b90f7532e1d9a90 100644 (file)
@@ -387,6 +387,20 @@ ply_key_file_get_bool (ply_key_file_t *key_file,
         return false;
 }
 
+double
+ply_key_file_get_double (ply_key_file_t *key_file,
+                         const char     *group,
+                         const char     *key,
+                         double          default_value)
+{
+        char *raw_value = ply_key_file_get_raw_value (key_file, group, key);
+
+        if (!raw_value)
+                return default_value;
+
+        return ply_strtod (raw_value);
+}
+
 static void
 ply_key_file_foreach_entry_entries (void *key,
                                     void *data,
index ef7124b586e347ad001a7d2e168ca8fc4a720478..f0610c95ca98be2e9fc691835a3d1dde22335557 100644 (file)
@@ -46,6 +46,10 @@ char *ply_key_file_get_value (ply_key_file_t *key_file,
 bool ply_key_file_get_bool (ply_key_file_t *key_file,
                             const char     *group_name,
                             const char     *key);
+double ply_key_file_get_double (ply_key_file_t *key_file,
+                                const char     *group_name,
+                                const char     *key,
+                                double          default_value);
 void ply_key_file_foreach_entry (ply_key_file_t             *key_file,
                                  ply_key_file_foreach_func_t func,
                                  void                       *user_data);