mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 01/12] file_list: Add function to add an entry to the list
Date: Wed, 27 Sep 2017 14:08:59 +0200	[thread overview]
Message-ID: <20170927120910.10516-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170927120910.10516-1-s.hauer@pengutronix.de>

Add file_list_add_entry() to add a single entry to a file_list. Then
use it in file_list_parse_one() instead of open coding adding a new
entry.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c  | 28 +++++++++++++++++++---------
 include/file-list.h |  3 +++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 90c0f429c5..010f8f0617 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -8,12 +8,26 @@
 #define PARSE_NAME	1
 #define PARSE_FLAGS	2
 
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+			unsigned long flags)
+{
+	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+
+	entry->name = xstrdup(name);
+	entry->filename = xstrdup(filename);
+	entry->flags = flags;
+
+	list_add_tail(&entry->list, &files->list);
+
+	return 0;
+}
+
 static int file_list_parse_one(struct file_list *files, const char *partstr, const char **endstr)
 {
 	int i = 0, state = PARSE_DEVICE;
 	char filename[PATH_MAX];
 	char name[PATH_MAX];
-	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+	unsigned long flags = 0;
 
 	memset(filename, 0, sizeof(filename));
 	memset(name, 0, sizeof(name));
@@ -39,13 +53,13 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 		case PARSE_FLAGS:
 			switch (*partstr) {
 			case 's':
-				entry->flags |= FILE_LIST_FLAG_SAFE;
+				flags |= FILE_LIST_FLAG_SAFE;
 				break;
 			case 'r':
-				entry->flags |= FILE_LIST_FLAG_READBACK;
+				flags |= FILE_LIST_FLAG_READBACK;
 				break;
 			case 'c':
-				entry->flags |= FILE_LIST_FLAG_CREATE;
+				flags |= FILE_LIST_FLAG_CREATE;
 				break;
 			default:
 				return -EINVAL;
@@ -60,15 +74,11 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 	if (state != PARSE_FLAGS)
 		return -EINVAL;
 
-	entry->name = xstrdup(name);
-	entry->filename = xstrdup(filename);
 	if (*partstr == ',')
 		partstr++;
 	*endstr = partstr;
 
-	list_add_tail(&entry->list, &files->list);
-
-	return 0;
+	return file_list_add_entry(files, name, filename, flags);
 }
 
 struct file_list *file_list_parse(const char *str)
diff --git a/include/file-list.h b/include/file-list.h
index 608181ff8d..ccdc2b5efd 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -20,6 +20,9 @@ struct file_list {
 struct file_list *file_list_parse(const char *str);
 void file_list_free(struct file_list *);
 
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+			unsigned long flags);
+
 #define file_list_for_each_entry(files, entry) \
 	list_for_each_entry(entry, &files->list, list)
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-09-27 12:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
2017-09-27 12:08 ` Sascha Hauer [this message]
2017-09-27 12:09 ` [PATCH 02/12] file_list: Add function to get entry by its name Sascha Hauer
2017-09-27 12:09 ` [PATCH 03/12] file_list: Allow only unique names on list Sascha Hauer
2017-09-27 12:09 ` [PATCH 04/12] file_list: Fix memory leak in failure path Sascha Hauer
2017-09-27 12:09 ` [PATCH 05/12] file_list: Add GPL header to file Sascha Hauer
2017-09-27 12:09 ` [PATCH 06/12] file_list: Add error messages Sascha Hauer
2017-09-27 12:09 ` [PATCH 07/12] usbgadget: fastboot: Use function to find file_list entry by name Sascha Hauer
2017-09-27 12:09 ` [PATCH 08/12] bbu: Add function to iterate over registered handlers Sascha Hauer
2017-09-27 12:09 ` [PATCH 09/12] usbgadget command: catch errors when parsing the file list Sascha Hauer
2017-09-27 12:09 ` [PATCH 10/12] usbgadget: fastboot: Allow to automatically export the bbu handlers Sascha Hauer
2017-09-27 12:09 ` [PATCH 11/12] fastboot command: Add -b option to export " Sascha Hauer
2017-09-27 12:09 ` [PATCH 12/12] usbgadget autostart: add usbgadget.fastboot_bbu to automatically " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170927120910.10516-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox