Exemplo n.º 1
0
VSIVirtualHandle* VSICurlStreamingFSHandler::Open( const char *pszFilename,
                                                   const char *pszAccess )
{
    if (strchr(pszAccess, 'w') != NULL ||
        strchr(pszAccess, '+') != NULL)
    {
        CPLError(CE_Failure, CPLE_AppDefined,
                 "Only read-only mode is supported for /vsicurl_streaming");
        return NULL;
    }

    VSICurlStreamingHandle* poHandle = new VSICurlStreamingHandle(
        this, pszFilename + strlen("/vsicurl_streaming/"));
    /* If we didn't get a filelist, check that the file really exists */
    if (!poHandle->Exists())
    {
        delete poHandle;
        poHandle = NULL;
    }

    if( CSLTestBoolean( CPLGetConfigOption( "VSI_CACHE", "FALSE" ) ) )
        return VSICreateCachedFile( poHandle );
    else
        return poHandle;
}
Exemplo n.º 2
0
VSIVirtualHandle *
VSIUnixStdioFilesystemHandler::Open( const char *pszFilename, 
                                     const char *pszAccess )

{
    FILE    *fp = VSI_FOPEN64( pszFilename, pszAccess );
    int     nError = errno;
    
    VSIDebug3( "VSIUnixStdioFilesystemHandler::Open(\"%s\",\"%s\") = %p",
               pszFilename, pszAccess, fp );

    if( fp == NULL )
    {
        errno = nError;
        return NULL;
    }

    VSIUnixStdioHandle *poHandle = new VSIUnixStdioHandle(this, fp);

    errno = nError;

/* -------------------------------------------------------------------- */
/*      If VSI_CACHE is set we want to use a cached reader instead      */
/*      of more direct io on the underlying file.                       */
/* -------------------------------------------------------------------- */
    if( (EQUAL(pszAccess,"r") || EQUAL(pszAccess,"rb"))
        && CSLTestBoolean( CPLGetConfigOption( "VSI_CACHE", "FALSE" ) ) )
    {
        return VSICreateCachedFile( poHandle );
    }
    else
    {
        return poHandle;
    }
}
Exemplo n.º 3
0
VSIVirtualHandle *VSIWin32FilesystemHandler::Open( const char *pszFilename, 
                                                   const char *pszAccess )

{
    DWORD dwDesiredAccess, dwCreationDisposition, dwFlagsAndAttributes;
    HANDLE hFile;

    if( strchr(pszAccess, '+') != NULL ||
        strchr(pszAccess, 'w') != 0 ||
        strchr(pszAccess, 'a') != 0 )
        dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
    else
        dwDesiredAccess = GENERIC_READ;

    if( strstr(pszAccess, "w") != NULL )
        dwCreationDisposition = CREATE_ALWAYS;
    else
        dwCreationDisposition = OPEN_EXISTING;

    dwFlagsAndAttributes = (dwDesiredAccess == GENERIC_READ) ? 
        FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL;
    
/* -------------------------------------------------------------------- */
/*      On Win32 consider treating the filename as utf-8 and            */
/*      converting to wide characters to open.                          */
/* -------------------------------------------------------------------- */
#ifndef WIN32CE
    if( CSLTestBoolean(
            CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )
    {
        wchar_t *pwszFilename = 
            CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 );

        hFile = CreateFileW( pwszFilename, dwDesiredAccess, 
                            FILE_SHARE_READ | FILE_SHARE_WRITE, 
                            NULL, dwCreationDisposition,  dwFlagsAndAttributes,
                            NULL );
        CPLFree( pwszFilename );
    }
    else
    {
        hFile = CreateFile( pszFilename, dwDesiredAccess, 
                            FILE_SHARE_READ | FILE_SHARE_WRITE, 
                            NULL, dwCreationDisposition,  dwFlagsAndAttributes,
                            NULL );
    }

/* -------------------------------------------------------------------- */
/*      On WinCE we only support plain ascii filenames.                 */
/* -------------------------------------------------------------------- */
#else /* def WIN32CE */
    hFile = CE_CreateFileA( pszFilename, dwDesiredAccess, 
                        FILE_SHARE_READ | FILE_SHARE_WRITE, 
                        NULL, dwCreationDisposition,  dwFlagsAndAttributes, NULL );
#endif

    if( hFile == INVALID_HANDLE_VALUE )
    {
        errno = ErrnoFromGetLastError();
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Create a VSI file handle.                                       */
/* -------------------------------------------------------------------- */
    VSIWin32Handle *poHandle = new VSIWin32Handle;
    
    poHandle->hFile = hFile;
    
    if (strchr(pszAccess, 'a') != 0)
        poHandle->Seek(0, SEEK_END);
    
/* -------------------------------------------------------------------- */
/*      If VSI_CACHE is set we want to use a cached reader instead      */
/*      of more direct io on the underlying file.                       */
/* -------------------------------------------------------------------- */
    if( (EQUAL(pszAccess,"r") || EQUAL(pszAccess,"rb"))
        && CSLTestBoolean( CPLGetConfigOption( "VSI_CACHE", "FALSE" ) ) )
    {
        return VSICreateCachedFile( poHandle );
    }
    else
    {
        return poHandle;
    }
}