No functional changes.
char *line;
size_t pos = 0;
char *key, *value;
- EFI_STATUS err;
assert(config);
assert(content);
config->entry_default_config = xstr8_to_16(value);
} else if (streq8(key, "editor")) {
- err = parse_boolean(value, &config->editor);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->editor))
log_error("Error parsing 'editor' config option, ignoring: %s", value);
} else if (streq8(key, "auto-entries")) {
- err = parse_boolean(value, &config->auto_entries);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->auto_entries))
log_error("Error parsing 'auto-entries' config option, ignoring: %s", value);
} else if (streq8(key, "auto-firmware")) {
- err = parse_boolean(value, &config->auto_firmware);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->auto_firmware))
log_error("Error parsing 'auto-firmware' config option, ignoring: %s", value);
} else if (streq8(key, "auto-poweroff")) {
- err = parse_boolean(value, &config->auto_poweroff);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->auto_poweroff))
log_error("Error parsing 'auto-poweroff' config option, ignoring: %s", value);
} else if (streq8(key, "auto-reboot")) {
- err = parse_boolean(value, &config->auto_reboot);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->auto_reboot))
log_error("Error parsing 'auto-reboot' config option, ignoring: %s", value);
} else if (streq8(key, "beep")) {
- err = parse_boolean(value, &config->beep);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->beep))
log_error("Error parsing 'beep' config option, ignoring: %s", value);
} else if (streq8(key, "reboot-for-bitlocker")) {
- err = parse_boolean(value, &config->reboot_for_bitlocker);
- if (err != EFI_SUCCESS)
+ if (!parse_boolean(value, &config->reboot_for_bitlocker))
log_error("Error parsing 'reboot-for-bitlocker' config option, ignoring: %s",
value);
DEFINE_PARSE_NUMBER(char, parse_number8);
DEFINE_PARSE_NUMBER(char16_t, parse_number16);
+bool parse_boolean(const char *v, bool *ret) {
+ assert(ret);
+
+ if (!v)
+ return false;
+
+ if (streq8(v, "1") || streq8(v, "yes") || streq8(v, "y") || streq8(v, "true") || streq8(v, "t") ||
+ streq8(v, "on")) {
+ *ret = true;
+ return true;
+ }
+
+ if (streq8(v, "0") || streq8(v, "no") || streq8(v, "n") || streq8(v, "false") || streq8(v, "f") ||
+ streq8(v, "off")) {
+ *ret = false;
+ return true;
+ }
+
+ return false;
+}
+
char16_t *hexdump(const void *data, size_t size) {
static const char hex[16] = "0123456789abcdef";
const uint8_t *d = data;
bool parse_number8(const char *s, uint64_t *ret_u, const char **ret_tail);
bool parse_number16(const char16_t *s, uint64_t *ret_u, const char16_t **ret_tail);
+bool parse_boolean(const char *v, bool *ret);
+
char16_t *hexdump(const void *data, size_t size);
#ifdef __clang__
assert_se(streq16(tail, u"rest"));
}
+TEST(parse_boolean) {
+ bool b;
+
+ assert_se(!parse_boolean(NULL, &b));
+ assert_se(!parse_boolean("", &b));
+ assert_se(!parse_boolean("ja", &b));
+ assert_se(parse_boolean("1", &b) && b == true);
+ assert_se(parse_boolean("y", &b) && b == true);
+ assert_se(parse_boolean("yes", &b) && b == true);
+ assert_se(parse_boolean("t", &b) && b == true);
+ assert_se(parse_boolean("true", &b) && b == true);
+ assert_se(parse_boolean("on", &b) && b == true);
+ assert_se(parse_boolean("0", &b) && b == false);
+ assert_se(parse_boolean("n", &b) && b == false);
+ assert_se(parse_boolean("no", &b) && b == false);
+ assert_se(parse_boolean("f", &b) && b == false);
+ assert_se(parse_boolean("false", &b) && b == false);
+ assert_se(parse_boolean("off", &b) && b == false);
+}
+
TEST(hexdump) {
char16_t *hex;
#include "util.h"
#include "version.h"
-EFI_STATUS parse_boolean(const char *v, bool *b) {
- assert(b);
-
- if (!v)
- return EFI_INVALID_PARAMETER;
-
- if (streq8(v, "1") || streq8(v, "yes") || streq8(v, "y") || streq8(v, "true") || streq8(v, "t") ||
- streq8(v, "on")) {
- *b = true;
- return EFI_SUCCESS;
- }
-
- if (streq8(v, "0") || streq8(v, "no") || streq8(v, "n") || streq8(v, "false") || streq8(v, "f") ||
- streq8(v, "off")) {
- *b = false;
- return EFI_SUCCESS;
- }
-
- return EFI_INVALID_PARAMETER;
-}
-
EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const char16_t *name, const void *buf, size_t size, uint32_t flags) {
assert(vendor);
assert(name);
};
}
-EFI_STATUS parse_boolean(const char *v, bool *b);
-
EFI_STATUS efivar_set(const EFI_GUID *vendor, const char16_t *name, const char16_t *value, uint32_t flags);
EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const char16_t *name, const void *buf, size_t size, uint32_t flags);
EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const char16_t *name, size_t i, uint32_t flags);