diff mbox series

handlers: bootloader: let comments and blankline in image

Message ID 20181201165144.21161-1-sbabic@denx.de
State Changes Requested
Headers show
Series handlers: bootloader: let comments and blankline in image | expand

Commit Message

Stefano Babic Dec. 1, 2018, 4:51 p.m. UTC
Allow to insert comments (line starting with '#') and blank lines for
bootloader images to increase readability. Fix crash when blank lines
are part of the image.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 handlers/boot_handler.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/handlers/boot_handler.c b/handlers/boot_handler.c
index 29fd190..cf41666 100644
--- a/handlers/boot_handler.c
+++ b/handlers/boot_handler.c
@@ -73,12 +73,28 @@  static int install_boot_environment(struct img_type *img,
 	while (fgets(buf, MAX_BOOT_SCRIPT_LINE_LENGTH, fp)) {
 		char **pair = NULL;
 		unsigned int cnt;
+		int len = strlen(buf);
+
+		while (len && (buf[len - 1] == '\n' || buf [len - 1] == '\r'))
+			buf[--len] = '\0';
+
+		/* Skip comment or empty lines */
+		if (len == 0 || buf[0] == '#')
+			continue;
 
 		pair = string_split(buf, '=');
 		cnt = count_string_array((const char **)pair);
 
-		if (cnt > 0 && strlen(pair[0]))
+		switch (cnt) {
+		case 2:
+			TRACE("name = %s value = %s", pair[0], pair[1]);
 			dict_set_value(img->bootloader, pair[0], pair[1]);
+			break;
+		case 1:
+			TRACE("name = %s Removed", pair[0]);
+			dict_remove(img->bootloader, pair[0]);
+			break;
+		}
 		free(pair);
 	}
 	fclose(fp);