mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-01 22:21:16 +02:00
layout: Extract parsing include args into a separate function
Change-Id: Iba2971846938fe95412f0a69ff3c069ee2d049b6 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/70539 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:

committed by
Edward O'Callaghan

parent
3985da4824
commit
51d9015dda
43
layout.c
43
layout.c
@ -114,42 +114,61 @@ _close_ret:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* register an include argument (-i) for later processing */
|
static bool parse_include_args(const char *arg, char **name, char **file)
|
||||||
int register_include_arg(struct layout_include_args **args, const char *arg)
|
|
||||||
{
|
{
|
||||||
struct layout_include_args *tmp;
|
|
||||||
char *colon;
|
char *colon;
|
||||||
char *name;
|
char *tmp_name;
|
||||||
char *file = NULL; /* file is optional, so defaults to NULL */
|
char *tmp_file = NULL; /* file is optional, so defaults to NULL */
|
||||||
|
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
msg_gerr("<NULL> is a bad region name.\n");
|
msg_gerr("<NULL> is a bad region name.\n");
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -i <image>[:<file>] */
|
/* -i <image>[:<file>] */
|
||||||
colon = strchr(arg, ':');
|
colon = strchr(arg, ':');
|
||||||
if (colon && !colon[1]) {
|
if (colon && !colon[1]) {
|
||||||
msg_gerr("Missing filename parameter in %s\n", arg);
|
msg_gerr("Missing filename parameter in %s\n", arg);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colon) {
|
if (colon) {
|
||||||
name = strndup(arg, colon - arg);
|
tmp_name = strndup(arg, colon - arg);
|
||||||
if (!name) {
|
if (!tmp_name) {
|
||||||
msg_gerr("Out of memory");
|
msg_gerr("Out of memory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = strdup(colon + 1);
|
tmp_file = strdup(colon + 1);
|
||||||
if (!file) {
|
if (!tmp_file) {
|
||||||
msg_gerr("Out of memory");
|
msg_gerr("Out of memory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = strdup(arg);
|
tmp_name = strdup(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*name = tmp_name;
|
||||||
|
*file = tmp_file;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(tmp_name);
|
||||||
|
free(tmp_file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* register an include argument (-i) for later processing */
|
||||||
|
int register_include_arg(struct layout_include_args **args, const char *arg)
|
||||||
|
{
|
||||||
|
struct layout_include_args *tmp;
|
||||||
|
char *name;
|
||||||
|
char *file;
|
||||||
|
|
||||||
|
if (!parse_include_args(arg, &name, &file))
|
||||||
|
return 1;
|
||||||
|
|
||||||
for (tmp = *args; tmp; tmp = tmp->next) {
|
for (tmp = *args; tmp; tmp = tmp->next) {
|
||||||
if (!strcmp(tmp->name, name)) {
|
if (!strcmp(tmp->name, name)) {
|
||||||
msg_gerr("Duplicate region name: \"%s\".\n", name);
|
msg_gerr("Duplicate region name: \"%s\".\n", name);
|
||||||
|
Reference in New Issue
Block a user