diff options
author | Stef Walter <stefw@gnome.org> | 2013-03-03 09:50:44 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-03 10:07:08 +0100 |
commit | ae76545a0094114ef29dba52df97e69ab28b3dbc (patch) | |
tree | 8052e7262deeba9962c31a13ec3f041507464678 /trust | |
parent | 38acf11889c1e1da2610c8e05f1f380f2a2a1ae6 (diff) |
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.
Diffstat (limited to 'trust')
-rw-r--r-- | trust/parser.c | 28 |
1 files changed, 7 insertions, 21 deletions
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 <libtasn1.h> -#include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> @@ -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; } |