zipl: Return number of allocated tokens in scan_file()

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 <javierm@redhat.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Javier Martinez Canillas
2018-05-02 12:26:49 +02:00
committed by Jan Höppner
parent d868ce5ec7
commit e04acab0ed
2 changed files with 13 additions and 11 deletions

View File

@@ -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);

View File

@@ -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;
}