From e04acab0ed20c4f60def97c4f52b80f6d4b226c3 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Wed, 2 May 2018 12:26:49 +0200 Subject: [PATCH] zipl: Return number of allocated tokens in scan_file() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function returns 0 on success and a negative number on error but is useful to know how many tokens were allocated. This will be used by the BLS parsing code to determine if needs to allocate mor tokens or not to parse the BLS fragments. GitHub-ID: #28 Signed-off-by: Javier Martinez Canillas Reviewed-by: Stefan Haberland Signed-off-by: Jan Höppner --- zipl/src/job.c | 8 ++++---- zipl/src/scan.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/zipl/src/job.c b/zipl/src/job.c index b06a4824..9d5f00b6 100644 --- a/zipl/src/job.c +++ b/zipl/src/job.c @@ -1732,7 +1732,7 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job) struct scan_token* new_scan; char* filename; char* source; - int rc; + int rc, scan_size; /* Read configuration file */ if (cmdline->config != NULL) { @@ -1750,10 +1750,10 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job) source = ""; } printf("Using config file '%s'%s\n", filename, source); - rc = scan_file(filename, &scan); - if (rc) { + scan_size = scan_file(filename, &scan); + if (scan_size <= 0) { error_text("Config file '%s'", filename); - return rc; + return scan_size; } if ((cmdline->menu == NULL) && (cmdline->section == NULL)) { rc = scan_check_defaultboot(scan); diff --git a/zipl/src/scan.c b/zipl/src/scan.c index 7465d6cc..adb288e0 100644 --- a/zipl/src/scan.c +++ b/zipl/src/scan.c @@ -538,9 +538,9 @@ scan_free(struct scan_token* array) #define INITIAL_ARRAY_LENGTH 40 -/* Scan file FILENAME for tokens. Upon success, return zero and set TOKEN - * to point to a NULL-terminated array of scan_tokens, i.e. the token id - * of the last token is 0. Return non-zero otherwise. */ +/* Scan file FILENAME for tokens. Upon success, return the number allocated + * tokens and set TOKEN to point to a NULL-terminated array of scan_tokens, + * i.e. the token id of the last token is 0. Return non-zero otherwise. */ int scan_file(const char* filename, struct scan_token** token) { @@ -623,11 +623,13 @@ scan_file(const char* filename, struct scan_token** token) } } misc_free_file_buffer(&file); - if (rc) + if (rc) { scan_free(array); - else - *token = array; - return rc; + return rc; + } + + *token = array; + return size; }