X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/ac27e6b4e9f2f269ad11856171ae8e1f51fa26f0..cf37c2996a8b83ccbcb7e2e413f749f6e60a3845:/CPPUtil/UtilMappedFile.cpp diff --git a/CPPUtil/UtilMappedFile.cpp b/CPPUtil/UtilMappedFile.cpp deleted file mode 100644 index acc71bd..0000000 --- a/CPPUtil/UtilMappedFile.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// UtilMappedFile.cpp -// CPPUtil -// -// Created by James McIlree on 4/19/13. -// Copyright (c) 2013 Apple. All rights reserved. -// - -#include "CPPUtil.h" - -#include - -BEGIN_UTIL_NAMESPACE - -static int open_fd(const char* path, size_t& file_size) -{ - int fd = open(path, O_RDONLY, 0); - if(fd >= 0) { - struct stat data; - if (fstat(fd, &data) == 0) { - if (S_ISREG(data.st_mode)) { - // Is it zero sized? - if (data.st_size > 0) { - file_size = (size_t)data.st_size; - return fd; - } - } - } - close(fd); - } - - return -1; -} - -MappedFile::MappedFile(const char* path) : - _address(NULL), - _size(0) -{ - ASSERT(path, "Sanity"); - int fd = open_fd(path, _size); - if (fd >= 0) { - _address = (unsigned char*)mmap(NULL, _size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); - if (_address == (void*)-1) { - _address = NULL; - } - close(fd); - } -} - -MappedFile::~MappedFile() -{ - if (_address != NULL) { - munmap(_address, _size); - } -} - -END_UTIL_NAMESPACE