summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2022-12-09 17:27:25 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2022-12-15 00:12:54 +0000
commit51d9015dda5e8748e25bc5309f808b1b06494b73 (patch)
tree0e14df76ebecf1d7aabe0e3c7eac5d3793d0537c /layout.c
parent3985da482405a85779c3fea00455018a0760212b (diff)
downloadflashrom-51d9015dda5e8748e25bc5309f808b1b06494b73.tar.gz
flashrom-51d9015dda5e8748e25bc5309f808b1b06494b73.tar.bz2
flashrom-51d9015dda5e8748e25bc5309f808b1b06494b73.zip
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>
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/layout.c b/layout.c
index 9cd3e016a..350e49eca 100644
--- a/layout.c
+++ b/layout.c
@@ -114,42 +114,61 @@ _close_ret:
}
#endif
-/* register an include argument (-i) for later processing */
-int register_include_arg(struct layout_include_args **args, const char *arg)
+static bool parse_include_args(const char *arg, char **name, char **file)
{
- struct layout_include_args *tmp;
char *colon;
- char *name;
- char *file = NULL; /* file is optional, so defaults to NULL */
+ char *tmp_name;
+ char *tmp_file = NULL; /* file is optional, so defaults to NULL */
if (arg == NULL) {
msg_gerr("<NULL> is a bad region name.\n");
- return 1;
+ return false;
}
/* -i <image>[:<file>] */
colon = strchr(arg, ':');
if (colon && !colon[1]) {
msg_gerr("Missing filename parameter in %s\n", arg);
- return 1;
+ return false;
}
if (colon) {
- name = strndup(arg, colon - arg);
- if (!name) {
+ tmp_name = strndup(arg, colon - arg);
+ if (!tmp_name) {
msg_gerr("Out of memory");
goto error;
}
- file = strdup(colon + 1);
- if (!file) {
+ tmp_file = strdup(colon + 1);
+ if (!tmp_file) {
msg_gerr("Out of memory");
goto error;
}
} 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) {
if (!strcmp(tmp->name, name)) {
msg_gerr("Duplicate region name: \"%s\".\n", name);