コード例 #1
0
MappedFile::MappedFile(const StringSlice& path)
        : _path(path),
          _size(0),
          _data(NULL) {
    CString c_path(path);
    _fd = open(c_path.data(), O_RDONLY, 0600);
    if (_fd < 0) {
        throw Exception(format("{0}: {1}", path, posix_strerror()));
    }
    ScopedFd close(_fd);

    struct stat st;
    if (fstat(_fd, &st) < 0) {
        throw Exception(format("{0}: {1}", path, posix_strerror()));
    }
    if (S_ISDIR(st.st_mode)) {
        throw Exception(format("{0}: {1}", path, posix_strerror(EISDIR)));
    }
    _size = st.st_size;

    _data = reinterpret_cast<uint8_t*>(mmap(NULL, _size, PROT_READ, MAP_PRIVATE, _fd, 0));
    if (_data == MAP_FAILED) {
        throw Exception(format("{0}: {1}", path, posix_strerror()));
    }

    close.release();
}
コード例 #2
0
ファイル: File.cpp プロジェクト: DeretsunGit/RType
bool File::operator==(const char* path) const
{
	Path c_path(path);

	if (_path.getAbsolutePath() == c_path.getAbsolutePath())
		return true;
	return false;
}