#include <regex.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
int pakfire_parser_read(struct pakfire_parser* parser, FILE* f,
struct pakfire_parser_error** error) {
- char* data;
- size_t len;
+ char* data = NULL;
+ size_t length = 0;
+ int fd = -EBADF;
+ int r;
- int r = pakfire_read_file_into_buffer(f, &data, &len);
- if (r)
+ // Fetch the file descriptor
+ fd = fileno(f);
+ if (fd < 0)
+ return fd;
+
+ // Map the file
+ r = pakfire_mmap(fd, &data, &length);
+ if (r < 0) {
+ ERROR(parser->ctx, "Could not map parser data into memory: %s\n", strerror(-r));
return r;
+ }
- r = pakfire_parser_parse_data(parser, data, len, error);
+ // Run the parser
+ r = pakfire_parser_parse_data(parser, data, length, error);
+ if (r < 0)
+ goto ERROR;
+ERROR:
if (data)
- free(data);
+ munmap(data, length);
return r;
}