Exemplo n.º 1
0
// create the file, fail if it already exists and bOverwrite
bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
{
    // if bOverwrite we create a new file or truncate the existing one,
    // otherwise we only create the new file and fail if it already exists
#if defined(__WXMAC__) && !defined(__UNIX__) && !wxUSE_UNICODE
    // Dominic Mazzoni [[email protected]] reports that open is still broken on the mac, so we replace
    // int fd = open( szFileName , O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
    int fd = creat( szFileName , accessMode);
#else
    int fd = wxOpen( szFileName,
                     O_BINARY | O_WRONLY | O_CREAT |
                     (bOverwrite ? O_TRUNC : O_EXCL)
                     ACCESS(accessMode) );
#endif
    if ( fd == -1 )
    {
        wxLogSysError(_("can't create file '%s'"), szFileName);
        return false;
    }
    else
    {
        Attach(fd);
        return true;
    }
}
Exemplo n.º 2
0
bool FlatFileReader::Open(const wxString& fileName)
{
	m_filename = fileName;

	int err = io_setup(64, &m_aio_context);
	if (err) return false;

    m_fd = wxOpen(fileName, O_RDONLY, 0);

	return (m_fd != -1);
}
Exemplo n.º 3
0
// open the file
bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode)
{
    int flags = O_BINARY;

    switch ( mode )
    {
        case read:
            flags |= O_RDONLY;
            break;

        case write_append:
            if ( wxFile::Exists(szFileName) )
            {
                flags |= O_WRONLY | O_APPEND;
                break;
            }
            //else: fall through as write_append is the same as write if the
            //      file doesn't exist

        case write:
            flags |= O_WRONLY | O_CREAT | O_TRUNC;
            break;

        case write_excl:
            flags |= O_WRONLY | O_CREAT | O_EXCL;
            break;

        case read_write:
            flags |= O_RDWR;
            break;
    }

#ifdef __WINDOWS__
    // only read/write bits for "all" are supported by this function under
    // Windows, and VC++ 8 returns EINVAL if any other bits are used in
    // accessMode, so clear them as they have at best no effect anyhow
    accessMode &= wxS_IRUSR | wxS_IWUSR;
#endif // __WINDOWS__

    int fd = wxOpen( szFileName, flags ACCESS(accessMode));

    if ( fd == -1 )
    {
        wxLogSysError(_("can't open file '%s'"), szFileName);
        return false;
    }
    else {
        Attach(fd);
        return true;
    }
}
Exemplo n.º 4
0
FitsFname::FitsFname(const wxString& path, bool create, bool clobber)
{
#ifdef __WINDOWS__

    if (create)
    {
        if (!clobber && wxFileExists(path))
        {
            m_str = new char[1];
            *m_str = 0;
            return;
        }

        int fd = wxOpen(path, O_BINARY | O_WRONLY | O_CREAT, wxS_DEFAULT);
        wxClose(fd);
    }

    // use the short DOS 8.3 path name to avoid problems converting UTF-16 filenames to the ANSI filenames expected by CFITTSIO

    DWORD shortlen = GetShortPathNameW(path.wc_str(), 0, 0);

    if (shortlen)
    {
        LPWSTR shortpath = new WCHAR[shortlen];
        GetShortPathNameW(path.wc_str(), shortpath, shortlen);
        int slen = WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortpath, shortlen, 0, 0, 0, 0);
        m_str = new char[slen + 1];
        char *str = m_str;
        if (create)
            *str++ = '!';
        WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortpath, shortlen, str, slen, 0, 0);
        delete[] shortpath;
    }
    else
    {
        m_str = new char[1];
        *m_str = 0;
    }

#else // __WINDOWS__

    if (clobber)
        m_str = (wxT("!") + path).fn_str();
    else
        m_str = path.fn_str();

#endif // __WINDOWS__
}
Exemplo n.º 5
0
// create the file, fail if it already exists and bOverwrite
bool wxFile::Create(const wxString& fileName, bool bOverwrite, int accessMode)
{
    // if bOverwrite we create a new file or truncate the existing one,
    // otherwise we only create the new file and fail if it already exists
    int fd = wxOpen( fileName,
                     O_BINARY | O_WRONLY | O_CREAT |
                     (bOverwrite ? O_TRUNC : O_EXCL),
                     accessMode );
    if ( CheckForError(fd) )
    {
        wxLogSysError(_("can't create file '%s'"), fileName);
        return false;
    }

    Attach(fd);
    return true;
}
Exemplo n.º 6
0
void LogTestCase::SysError()
{
    wxString s;

    wxLogSysError(17, "Error");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Error (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 17") );

    // The last error code seems to be set somewhere in MinGW CRT as its value
    // is just not what we expect (ERROR_INVALID_PARAMETER instead of 0 and 0
    // instead of ERROR_FILE_NOT_FOUND) so exclude the tests which rely on last
    // error being preserved for this compiler.
#ifndef __MINGW32__
    wxLogSysError("Success");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Success (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 0") );

    wxOpen("no-such-file", 0, 0);
    wxLogSysError("Not found");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Not found (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 2") );
#endif // __MINGW32__
}
Exemplo n.º 7
0
void LogTestCase::SysError()
{
    wxString s;

    wxLogSysError(17, "Error");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Error (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 17") );

    // Try to ensure that the system error is 0.
#ifdef __WINDOWS__
    ::SetLastError(0);
#else
    errno = 0;
#endif

    wxLogSysError("Success");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Success (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 0") );

    wxOpen("no-such-file", 0, 0);
    wxLogSysError("Not found");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Not found (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 2") );
}