summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-10-15 09:54:48 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-10-19 08:39:18 +0200
commit119f75f23a92b5171978a6691fd10e12247628ea (patch)
tree45e679665271d4c92c81b4292781320f91202189
parentbf16227fe8da6a7e4a63489c12e280005db4dfd9 (diff)
downloadbarebox-119f75f23a92b5171978a6691fd10e12247628ea.tar.gz
barebox-119f75f23a92b5171978a6691fd10e12247628ea.tar.xz
scripts/kwbimage: Move configfile opening to the function that reads it
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>
-rw-r--r--scripts/kwbimage.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 5b8e73892c..16be2dda1b 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;