FILE *VSIFOpen( const char * pszFilename, const char * pszAccess ) { FILE *fp = NULL; int nError; #if defined(WIN32) && !defined(WIN32CE) if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); wchar_t *pwszAccess = CPLRecodeToWChar( pszAccess, CPL_ENC_UTF8, CPL_ENC_UCS2 ); fp = _wfopen( pwszFilename, pwszAccess ); CPLFree( pwszFilename ); CPLFree( pwszAccess ); } else #endif fp = fopen( (char *) pszFilename, (char *) pszAccess ); nError = errno; VSIDebug3( "VSIFOpen(%s,%s) = %p", pszFilename, pszAccess, fp ); errno = nError; return( fp ); }
int VSIWin32FilesystemHandler::Rename( const char *oldpath, const char *newpath ) { #if (defined(WIN32) && _MSC_VER >= 1310) || __MSVCRT_VERSION__ >= 0x0601 if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { int nResult; wchar_t *pwszOldPath = CPLRecodeToWChar( oldpath, CPL_ENC_UTF8, CPL_ENC_UCS2 ); wchar_t *pwszNewPath = CPLRecodeToWChar( newpath, CPL_ENC_UTF8, CPL_ENC_UCS2 ); nResult = _wrename( pwszOldPath, pwszNewPath ); CPLFree( pwszOldPath ); CPLFree( pwszNewPath ); return nResult; } else #endif { return rename( oldpath, newpath ); } }
FILE *VSIFOpen( const char * pszFilename, const char * pszAccess ) { FILE *fp = NULL; #if defined(WIN32) if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); wchar_t *pwszAccess = CPLRecodeToWChar( pszAccess, CPL_ENC_UTF8, CPL_ENC_UCS2 ); fp = _wfopen( pwszFilename, pwszAccess ); CPLFree( pwszFilename ); CPLFree( pwszAccess ); } else #endif fp = fopen( (char *) pszFilename, (char *) pszAccess ); #ifdef VSI_DEBUG // Capture the error from fopen to avoid being overwritten by errors // from VSIDebug3. const int nError = errno; VSIDebug3( "VSIFOpen(%s,%s) = %p", pszFilename, pszAccess, fp ); errno = nError; #endif return fp; }
void tr_strcpy( XMLCh *panXMLString, const char *pszCString ) { /* -------------------------------------------------------------------- */ /* Simple (ASCII) case. */ /* -------------------------------------------------------------------- */ if( tr_isascii( pszCString ) ) { while( *pszCString != 0 ) *(panXMLString++) = *(pszCString++); *panXMLString = 0; return; } /* -------------------------------------------------------------------- */ /* Otherwise we need to do a full UTC2 to UTF-8 conversion. */ /* -------------------------------------------------------------------- */ wchar_t *pwszUTF16; pwszUTF16 = CPLRecodeToWChar( pszCString, CPL_ENC_UTF8, "WCHAR_T" ); int i = 0; for( ; pwszUTF16[i] != 0; i++ ) panXMLString[i] = pwszUTF16[i]; panXMLString[i] = 0; CPLFree( pwszUTF16 ); }
int VSIWin32FilesystemHandler::Stat( const char * pszFilename, VSIStatBufL * pStatBuf, int nFlags ) { (void) nFlags; #if (defined(WIN32) && _MSC_VER >= 1310) || __MSVCRT_VERSION__ >= 0x0601 if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { int nResult; wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); nResult = _wstat64( pwszFilename, pStatBuf ); CPLFree( pwszFilename ); return nResult; } else #endif { return( VSI_STAT64( pszFilename, pStatBuf ) ); } }
CPLString OGRDXFWriterLayer::TextEscape( const char *pszInput ) { CPLString osResult; wchar_t *panInput = CPLRecodeToWChar( pszInput, CPL_ENC_UTF8, CPL_ENC_UCS2 ); int i; for( i = 0; panInput[i] != 0; i++ ) { if( panInput[i] == '\n' ) osResult += "\\P"; else if( panInput[i] == ' ' ) osResult += "\\~"; else if( panInput[i] == '\\' ) osResult += "\\\\"; else if( panInput[i] > 255 ) { CPLString osUnicode; osUnicode.Printf( "\\U+%04x", (int) panInput[i] ); osResult += osUnicode; } else osResult += (char) panInput[i]; } CPLFree(panInput); return osResult; }
void *CPLGetSymbol( const char * pszLibrary, const char * pszSymbolName ) { void *pLibrary = nullptr; void *pSymbol = nullptr; // Avoid error boxes to pop up (#5211, #5525). UINT uOldErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); #if defined(_MSC_VER) || __MSVCRT_VERSION__ >= 0x0601 if( CPLTestBool( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { wchar_t *pwszFilename = CPLRecodeToWChar( pszLibrary, CPL_ENC_UTF8, CPL_ENC_UCS2 ); pLibrary = LoadLibraryW(pwszFilename); CPLFree( pwszFilename ); } else #endif { pLibrary = LoadLibraryA(pszLibrary); } if( pLibrary <= (void*)HINSTANCE_ERROR ) { LPVOID lpMsgBuf = nullptr; int nLastError = GetLastError(); // Restore old error mode. SetErrorMode(uOldErrorMode); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, nLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>(&lpMsgBuf), 0, nullptr ); CPLError( CE_Failure, CPLE_AppDefined, "Can't load requested DLL: %s\n%d: %s", pszLibrary, nLastError, static_cast<const char *>(lpMsgBuf) ); return nullptr; } // Restore old error mode. SetErrorMode(uOldErrorMode); pSymbol = reinterpret_cast<void *>(GetProcAddress( static_cast<HINSTANCE>(pLibrary), pszSymbolName )); if( pSymbol == nullptr ) { CPLError( CE_Failure, CPLE_AppDefined, "Can't find requested entry point: %s", pszSymbolName ); return nullptr; } return( pSymbol ); }
int VSIStat( const char * pszFilename, VSIStatBuf * pStatBuf ) { #if defined(WIN32) && !defined(WIN32CE) if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { int nResult; wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); nResult = _wstat( pwszFilename, (struct _stat *) pStatBuf ); CPLFree( pwszFilename ); return nResult; } else #endif return( stat( pszFilename, pStatBuf ) ); }
int VSIWin32FilesystemHandler::Rmdir( const char * pszPathname ) { #if (defined(WIN32) && _MSC_VER >= 1310) || __MSVCRT_VERSION__ >= 0x0601 if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) { int nResult; wchar_t *pwszFilename = CPLRecodeToWChar( pszPathname, CPL_ENC_UTF8, CPL_ENC_UCS2 ); nResult = _wrmdir( pwszFilename ); CPLFree( pwszFilename ); return nResult; } else #endif { return rmdir( pszPathname ); } }
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; } }