Esempio n. 1
0
Error
File::Duplicate (const File &rhs)
{
    Error error;
    if (IsValid ())
        Close();

    if (rhs.DescriptorIsValid())
    {
#ifdef _WIN32
        m_descriptor = ::_dup(rhs.GetDescriptor());
#else
        m_descriptor = ::fcntl(rhs.GetDescriptor(), F_DUPFD);
#endif
        if (!DescriptorIsValid())
            error.SetErrorToErrno();
        else
        {
            m_options = rhs.m_options;
            m_own_descriptor = true;
        }
    }
    else
    {
        error.SetErrorString ("invalid file to duplicate");
    }
    return error;
}
Esempio n. 2
0
//----------------------------------------------------------------------
// Memory map "length" bytes from "file" starting "offset"
// bytes into the file. If "length" is set to SIZE_MAX, then
// map as many bytes as possible.
//
// Returns the number of bytes mapped starting from the requested
// offset.
//----------------------------------------------------------------------
size_t
DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* file, 
                                            off_t offset, 
                                            size_t length,
                                            bool writeable)
{
    if (file != NULL)
    {
        char path[PATH_MAX];
        if (file->GetPath(path, sizeof(path)))
        {
            uint32_t options = File::eOpenOptionRead;
            if (writeable)
                options |= File::eOpenOptionWrite;

            File file;
            Error error (file.Open(path, options));
            if (error.Success())
            {
                const bool fd_is_file = true;
                MemoryMapFromFileDescriptor (file.GetDescriptor(), offset, length, writeable, fd_is_file);
                return GetByteSize();
            }
        }
    }
    // We should only get here if there was an error
    Clear();
    return 0;
}
Esempio n. 3
0
void
PythonFile::Reset(File &file, const char *mode)
{
    char *cmode = const_cast<char *>(mode);
#if PY_MAJOR_VERSION >= 3
    Reset(PyRefType::Owned,
        PyFile_FromFd(file.GetDescriptor(), nullptr, cmode, -1, nullptr, "ignore", nullptr, 0));
#else
    // Read through the Python source, doesn't seem to modify these strings
    Reset(PyRefType::Owned,
        PyFile_FromFile(file.GetStream(), const_cast<char *>(""), cmode, nullptr));
#endif
}
Esempio n. 4
0
//----------------------------------------------------------------------
// Memory map "length" bytes from "file" starting "offset"
// bytes into the file. If "length" is set to SIZE_MAX, then
// map as many bytes as possible.
//
// Returns the number of bytes mapped starting from the requested
// offset.
//----------------------------------------------------------------------
size_t
DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* filespec,
                                            lldb::offset_t offset,
                                            size_t length,
                                            bool writeable)
{
    if (filespec != NULL)
    {
        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP));
        if (log)
        {
            log->Printf("DataBufferMemoryMap::MemoryMapFromFileSpec(file=\"%s\", offset=0x%" PRIx64 ", length=0x%" PRIx64 ", writeable=%i",
                        filespec->GetPath().c_str(),
                        offset,
                        (uint64_t)length,
                        writeable);
        }
        char path[PATH_MAX];
        if (filespec->GetPath(path, sizeof(path)))
        {
            uint32_t options = File::eOpenOptionRead;
            if (writeable)
                options |= File::eOpenOptionWrite;

            File file;
            Error error (file.Open(path, options));
            if (error.Success())
            {
                const bool fd_is_file = true;
                return MemoryMapFromFileDescriptor (file.GetDescriptor(), offset, length, writeable, fd_is_file);
            }
        }
    }
    // We should only get here if there was an error
    Clear();
    return 0;
}