mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-08 10:08:06 +02:00
libply: Add ply_key_file_get_bool function
Add a function to read a boolean value from a ply-key-file. This function will return true if the key exists and it has a value of "1", "y", "yes" or "true" (case-insensitive). In all other cases it returns false. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
c8f12565fb
commit
e111ba8baf
2 changed files with 37 additions and 0 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -356,6 +357,38 @@ ply_key_file_get_value (ply_key_file_t *key_file,
|
|||
return strdup (entry->value);
|
||||
}
|
||||
|
||||
bool
|
||||
ply_key_file_get_bool (ply_key_file_t *key_file,
|
||||
const char *group_name,
|
||||
const char *key)
|
||||
{
|
||||
ply_key_file_group_t *group;
|
||||
ply_key_file_entry_t *entry;
|
||||
|
||||
group = ply_key_file_find_group (key_file, group_name);
|
||||
|
||||
if (group == NULL) {
|
||||
ply_trace ("key file does not have group '%s'", group_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
entry = ply_key_file_find_entry (key_file, group, key);
|
||||
|
||||
if (entry == NULL) {
|
||||
ply_trace ("key file does not have entry for key '%s'", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* We treat "1", "y" and "yes" and "true" as true, all else is false */
|
||||
if (strcasecmp (entry->value, "1") == 0 ||
|
||||
strcasecmp (entry->value, "y") == 0 ||
|
||||
strcasecmp (entry->value, "yes") == 0 ||
|
||||
strcasecmp (entry->value, "true") == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
ply_key_file_foreach_entry_entries (void *key,
|
||||
void *data,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ bool ply_key_file_has_key (ply_key_file_t *key_file,
|
|||
char *ply_key_file_get_value (ply_key_file_t *key_file,
|
||||
const char *group_name,
|
||||
const char *key);
|
||||
/* Note this returns false for non existing keys */
|
||||
bool ply_key_file_get_bool (ply_key_file_t *key_file,
|
||||
const char *group_name,
|
||||
const char *key);
|
||||
void ply_key_file_foreach_entry (ply_key_file_t *key_file,
|
||||
ply_key_file_foreach_func_t func,
|
||||
void *user_data);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue