Skip to content
Snippets Groups Projects
Commit 1e0f45bf authored by Daniel Salzman's avatar Daniel Salzman
Browse files

yparser: fix empty file processing

parent 97f58c29
No related branches found
No related tags found
1 merge request!357New Configuration
......@@ -109,16 +109,25 @@ int yp_set_input_file(
return KNOT_EFILE;
}
// Map the file to the memory.
char *start = mmap(0, file_stat.st_size, PROT_READ, MAP_SHARED,
parser->file.descriptor, 0);
if (start == MAP_FAILED) {
close(parser->file.descriptor);
return KNOT_ENOMEM;
}
char *start = NULL;
// Check for empty file (cannot mmap).
if (file_stat.st_size > 0) {
// Map the file to the memory.
start = mmap(0, file_stat.st_size, PROT_READ, MAP_SHARED,
parser->file.descriptor, 0);
if (start == MAP_FAILED) {
close(parser->file.descriptor);
return KNOT_ENOMEM;
}
// Try to set the mapped memory advise to sequential.
(void)madvise(start, file_stat.st_size, MADV_SEQUENTIAL);
// Try to set the mapped memory advise to sequential.
(void)madvise(start, file_stat.st_size, MADV_SEQUENTIAL);
parser->input.eof = false;
} else {
parser->input.eof = true;
}
parser->file.name = strdup(file_name);
......@@ -126,7 +135,6 @@ int yp_set_input_file(
parser->input.start = start;
parser->input.current = start;
parser->input.end = start + file_stat.st_size;
parser->input.eof = false;
return KNOT_EOK;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment