From ae76545a0094114ef29dba52df97e69ab28b3dbc Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 3 Mar 2013 09:50:44 +0100 Subject: Abstract mmap() into a compat API The Win32 for mmap() is very different from Unix, so abstract this into our own p11_mmap_xxx() functions. --- trust/parser.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'trust') diff --git a/trust/parser.c b/trust/parser.c index 6229d09..3448f40 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -52,7 +52,6 @@ #include -#include #include #include @@ -1043,33 +1042,20 @@ p11_parse_file (p11_parser *parser, p11_parser_sink sink, void *sink_data) { + p11_mmap *map; void *data; - struct stat sb; - int fd; + size_t size; int ret; - fd = open (filename, O_RDONLY); - if (fd == -1) { - p11_message ("couldn't open file: %s: %s", filename, strerror (errno)); + map = p11_mmap_open (filename, &data, &size); + if (map == NULL) { + p11_message ("couldn't open and map file: %s: %s", filename, strerror (errno)); return P11_PARSE_FAILURE; } - if (fstat (fd, &sb) < 0) { - p11_message ("couldn't stat file: %s: %s", filename, strerror (errno)); - return P11_PARSE_FAILURE; - } - - data = mmap (NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (data == NULL) { - p11_message ("couldn't map file: %s: %s", filename, strerror (errno)); - return P11_PARSE_FAILURE; - } - - ret = p11_parse_memory (parser, filename, flags, data, sb.st_size, sink, sink_data); - - munmap (data, sb.st_size); - close (fd); + ret = p11_parse_memory (parser, filename, flags, data, size, sink, sink_data); + p11_mmap_close (map); return ret; } -- cgit v1.1