kern/env: Add function for retrieving variables as booleans

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Robbie Harwood 2022-11-04 12:13:35 -04:00 committed by Daniel Kiper
parent 229b23a017
commit b20192f22c
2 changed files with 14 additions and 0 deletions

View File

@ -144,6 +144,19 @@ grub_env_get (const char *name)
return var->value;
}
bool
grub_env_get_bool (const char *name, bool if_unset)
{
const char *val = grub_env_get (name);
if (val == NULL || grub_strlen (val) < 1)
return if_unset;
if (grub_strcmp (val, "0") == 0 || grub_strcmp (val, "false") == 0 ||
grub_strcmp (val, "disable") == 0 || grub_strcmp (val, "no") == 0)
return false;
return true;
}
void
grub_env_unset (const char *name)
{

View File

@ -45,6 +45,7 @@ struct grub_env_var
grub_err_t EXPORT_FUNC(grub_env_set) (const char *name, const char *val);
const char *EXPORT_FUNC(grub_env_get) (const char *name);
bool EXPORT_FUNC(grub_env_get_bool) (const char *name, bool if_unset);
void EXPORT_FUNC(grub_env_unset) (const char *name);
struct grub_env_var *EXPORT_FUNC(grub_env_update_get_sorted) (void);