summaryrefslogtreecommitdiff
path: root/files.c
diff options
context:
space:
mode:
authorJagger <robert@swiecki.net>2016-07-23 03:50:32 +0200
committerJagger <robert@swiecki.net>2016-07-23 03:50:32 +0200
commit41e7ffc6bf3436bdf461a6ba1fbc45ed6a079bbd (patch)
tree0ec1096d8806108d4ad08ad309b544ff9ee14888 /files.c
parent031129def83244ebfa053644796f4c26761f5d1b (diff)
downloadhonggfuzz-41e7ffc6bf3436bdf461a6ba1fbc45ed6a079bbd.tar.gz
Experimental - sancov: A very naive method of reading raw files
Diffstat (limited to 'files.c')
-rw-r--r--files.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/files.c b/files.c
index b818e40d..7f781f41 100644
--- a/files.c
+++ b/files.c
@@ -463,6 +463,31 @@ uint8_t *files_mapFile(char *fileName, off_t * fileSz, int *fd, bool isWritable)
return buf;
}
+uint8_t *files_mapFileShared(char *fileName, off_t * fileSz, int *fd)
+{
+ if ((*fd = open(fileName, O_RDONLY)) == -1) {
+ PLOG_E("Couldn't open() '%s' file in R/O mode", fileName);
+ return NULL;
+ }
+
+ struct stat st;
+ if (fstat(*fd, &st) == -1) {
+ PLOG_E("Couldn't stat() the '%s' file", fileName);
+ close(*fd);
+ return NULL;
+ }
+
+ uint8_t *buf;
+ if ((buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, *fd, 0)) == MAP_FAILED) {
+ PLOG_E("Couldn't mmap() the '%s' file", fileName);
+ close(*fd);
+ return NULL;
+ }
+
+ *fileSz = st.st_size;
+ return buf;
+}
+
bool files_readPidFromFile(const char *fileName, pid_t * pidPtr)
{
FILE *fPID = fopen(fileName, "rb");