int res = -1;
size_t input_size = lseek(input_fd, 0, SEEK_END);
lseek(input_fd, 0, SEEK_SET);
- void *input_file_ptr = mmap(NULL, input_size, PROT_READ, MAP_PRIVATE, input_fd, 0);
+ void *input_file_ptr = MAP_FAILED;
+ void *output_file_ptr = MAP_FAILED;
+
+ input_file_ptr = mmap(NULL, input_size, PROT_READ, MAP_PRIVATE, input_fd, 0);
if (input_file_ptr == MAP_FAILED) {
printf("Can not mmap input file: %d - %m\n", errno);
goto exit;
goto exit;
}
- void *output_file_ptr = mmap(NULL, max_output_size, PROT_WRITE, MAP_SHARED, output_fd, 0);
+ output_file_ptr = mmap(NULL, max_output_size, PROT_WRITE, MAP_SHARED, output_fd, 0);
if (output_file_ptr == MAP_FAILED) {
printf("Can not mmap output file: %d - %m\n", errno);
goto exit;
res = 0;
exit:
- if (input_file_ptr)
+ if (input_file_ptr != MAP_FAILED)
munmap(input_file_ptr, input_size);
- if (output_file_ptr)
+ if (output_file_ptr != MAP_FAILED)
munmap(output_file_ptr, max_output_size);
return res;