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>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Subject: [PATCH 1/3] scripts/kwbimage: Move configfile opening to the function that reads it
Date: Thu, 15 Oct 2015 10:18:54 +0200	[thread overview]
Message-ID: <1444897136-25028-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1444897136-25028-1-git-send-email-s.hauer@pengutronix.de>

The configfile is read in image_create_config_parse(), so move opening
the file to there aswell and pass the configfile as filename instead of
FILE *.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/kwbimage.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 5b8e738..16be2dd 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -1098,12 +1098,20 @@ static int image_create_config_parse_oneline(char *line,
  * elements 'image_cfg', and return the number of configuration
  * elements in 'cfgn'.
  */
-static int image_create_config_parse(FILE *fcfg,
+static int image_create_config_parse(const char *input,
 				     struct image_cfg_element *image_cfg,
 				     int *cfgn)
 {
 	int ret;
 	int cfgi = 0;
+	FILE *fcfg;
+
+	fcfg = fopen(input, "r");
+	if (!fcfg) {
+		fprintf(stderr, "Could not open input file %s\n",
+			input);
+		return -1;
+	}
 
 	/* Parse the configuration file */
 	while (!feof(fcfg)) {
@@ -1128,18 +1136,22 @@ static int image_create_config_parse(FILE *fcfg,
 		ret = image_create_config_parse_oneline(line,
 							&image_cfg[cfgi]);
 		if (ret)
-			return ret;
+			goto out;
 
 		cfgi++;
 
 		if (cfgi >= IMAGE_CFG_ELEMENT_MAX) {
 			fprintf(stderr, "Too many configuration elements in .cfg file\n");
-			return -1;
+			ret = -1;
+			goto out;
 		}
 	}
 
+	ret = 0;
 	*cfgn = cfgi;
-	return 0;
+out:
+	fclose(fcfg);
+	return ret;
 }
 
 static int image_override_payload(struct image_cfg_element *image_cfg,
@@ -1316,34 +1328,24 @@ static int image_create(const char *input, const char *output,
 			int verbose)
 {
 	struct image_cfg_element *image_cfg;
-	FILE *fcfg, *outputimg;
+	FILE *outputimg;
 	void *image = NULL;
 	int version;
 	size_t imagesz;
 	int cfgn;
 	int ret;
 
-	fcfg = fopen(input, "r");
-	if (!fcfg) {
-		fprintf(stderr, "Could not open input file %s\n",
-			input);
-		return -1;
-	}
-
 	image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX *
 			   sizeof(struct image_cfg_element));
 	if (!image_cfg) {
 		fprintf(stderr, "Cannot allocate memory\n");
-		fclose(fcfg);
 		return -1;
 	}
 
 	memset(image_cfg, 0,
 	       IMAGE_CFG_ELEMENT_MAX * sizeof(struct image_cfg_element));
-	rewind(fcfg);
 
-	ret = image_create_config_parse(fcfg, image_cfg, &cfgn);
-	fclose(fcfg);
+	ret = image_create_config_parse(input, image_cfg, &cfgn);
 	if (ret) {
 		free(image_cfg);
 		return -1;
-- 
2.6.1


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

  reply	other threads:[~2015-10-15  8:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15  8:18 Sascha Hauer
2015-10-15  8:18 ` Sascha Hauer [this message]
2015-10-15  8:18 ` [PATCH 2/3] scripts/kwbimage: Make BINARY files relative to config file Sascha Hauer
2015-10-15  9:00   ` Thomas Petazzoni
2015-10-15  9:29     ` Sebastian Hesselbarth
2015-10-15  9:44       ` Thomas Petazzoni
2015-10-19  6:40       ` Sascha Hauer
2015-10-15 10:44     ` Sascha Hauer
2015-10-15  8:18 ` [PATCH 3/3] ARM: mvebu: Lenovo IX4 300D: Fix pblb generation 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=1444897136-25028-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=thomas.petazzoni@free-electrons.com \
    /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