diff options
author | Jagger <robert@swiecki.net> | 2016-07-23 03:50:32 +0200 |
---|---|---|
committer | Jagger <robert@swiecki.net> | 2016-07-23 03:50:32 +0200 |
commit | 41e7ffc6bf3436bdf461a6ba1fbc45ed6a079bbd (patch) | |
tree | 0ec1096d8806108d4ad08ad309b544ff9ee14888 /files.c | |
parent | 031129def83244ebfa053644796f4c26761f5d1b (diff) | |
download | honggfuzz-41e7ffc6bf3436bdf461a6ba1fbc45ed6a079bbd.tar.gz |
Experimental - sancov: A very naive method of reading raw files
Diffstat (limited to 'files.c')
-rw-r--r-- | files.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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"); |