From c90a5743b3c066768ad3198d48256c4a98a786cd Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Mon, 29 Nov 2010 22:08:01 +0100 Subject: [PATCH] Parser: Use read() instead of mmap() --- src/parse.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/parse.c b/src/parse.c index dcca36c..be1641f 100644 --- a/src/parse.c +++ b/src/parse.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -183,19 +182,22 @@ parse_keywords(const char *filename) return NULL; } + buf = zmalloc(st.st_size+1); + + if (read(fd, buf, st.st_size) == -1) { + warn("%s", filename); + free(buf); + close(fd); + return NULL; + } + + buf[st.st_size] = '\0'; + file = zcalloc(sizeof(*file)); bufname = zcalloc(sizeof(*bufname) * BUFSIZ); file->name = strdup(path); file->parent = NULL; - buf = (char *)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, SEEK_SET); - - if (buf == (char*)MAP_FAILED) { - warn("%s", filename); - return NULL; - } - - for(i = 0, j = 0, line = 1; i < (size_t)st.st_size; i++) { if (!head && tail) @@ -303,7 +305,7 @@ parse_keywords(const char *filename) bufname[j++] = buf[i]; } - munmap(buf, st.st_size); + free(buf); free(bufname); warnx("%s read", file->name);