// Module : SALOME
//
#include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
std::string GetTmpDirByEnv( const std::string& tmp_path_env )
{
+#if defined WIN32 && defined UNICODE
+ std::wstring w_tmp_path_env = utf8_decode_s( tmp_path_env );
+ wchar_t* val = _wgetenv( w_tmp_path_env.c_str() );
+ std::string dir = val ? utf8_encode_s(val) : "";
+#else
char* val = getenv( tmp_path_env.c_str() );
- std::string dir = val ? val : "";
+ std::string dir = val ? val : "";
+#endif
return GetTmpDirByPath( dir );
}
if ( aTmpDir == "" || !IsExists( aTmpDir ))
{
#ifdef WIN32
+#ifdef UNICODE
+ wchar_t *wTmp_dir = _wgetenv( L"TEMP" );
+ if ( wTmp_dir == NULL ) {
+ wTmp_dir = _wgetenv(L"TMP");
+ if (wTmp_dir == NULL)
+ wTmp_dir = L"C:\\";
+ }
+ aTmpDir = utf8_encode_s( wTmp_dir );
+#else
char *Tmp_dir = getenv("TEMP");
if ( Tmp_dir == NULL )
{
}
else
aTmpDir = Tmp_dir;
+#endif
#else
aTmpDir = "/tmp/";
#endif
if ( aDir.back() != _separator_ ) aDir += _separator_;
-#ifdef WIN32
- CreateDirectory( aDir.c_str(), NULL );
+#ifdef WIN32
+#ifdef UNICODE
+ std::wstring aDirToCreate = utf8_decode_s(aDir);
+#else
+ std::string aDirToCreate = aDir;
+#endif
+ CreateDirectory( aDirToCreate.c_str(), NULL );
#else
mkdir( aDir.c_str(), 0x1ff );
#endif
-
return aDir;
}
//============================================================================
bool IsExists(const std::string& thePath)
{
+#if defined WIN32 && defined UNICODE
+ int status = _waccess( utf8_decode_s( thePath).c_str(), F_OK );
+#else
int status = access ( thePath.c_str() , F_OK );
+#endif
if (status != 0) return false;
return true;
}
// function : IsWritable
// purpose : Returns True(False) if the path is (not) writable
//============================================================================
- bool IsWritable(const std::string& thePath)
+ bool IsWritable(const std::string& thePath)
{
-#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
+#ifdef WIN32
+#ifdef UNICODE
+ std::wstring aPathToCheck = utf8_decode_s( thePath );
+#else
+ std::string aPathToCheck = thePath;
+#endif
+ if ( GetFileAttributes ( aPathToCheck.c_str() ) == 0xFFFFFFFF ) {
if ( GetLastError () == FILE_ATTRIBUTE_READONLY ) {
return false;
}
#ifdef WIN32
WIN32_FIND_DATA aFileData;
- HANDLE hFile = FindFirstFile( thePath.c_str(), &aFileData );
+#ifdef UNICODE
+ std::wstring aPathToCheck = utf8_decode_s(thePath);
+#else
+ std::string aPathToCheck = thePath;
+#endif
+
+ HANDLE hFile = FindFirstFile( aPathToCheck.c_str(), &aFileData );
if ( hFile == INVALID_HANDLE_VALUE )
{
//empty dir
-// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
{
int ls = 100, r = 1;
char *s;
-
+
while (ls < 10000 && r)
{
ls *= 2;
s = new char[ls];
r = gethostname(s, ls-1);//threadsafe see man 7 pthread
- switch (r)
+ switch (r)
{
case 0:
break;
case ENAMETOOLONG:
#endif
#ifdef WIN32
- case WSAEFAULT:
+ case WSAEFAULT:
#endif
delete [] s;
continue;
}
-
+
}
-
+
if (r != 0)
{
s = new char[50];
strcpy(s, "localhost");
}
-
+
// remove all after '.'
char *aDot = (strchr(s,'.'));
if (aDot) aDot[0] = '\0';
-
+
std::string p = s;
delete [] s;
return p;
}
-
+
Localizer::Localizer()
{
myCurLocale = setlocale(LC_NUMERIC, 0);
#endif
#endif
+#if defined(WIN32)
+ // Convert a wide Unicode string to an UTF8 string
+ char* utf8_encode(const wchar_t* encoded)
+ {
+ if (encoded == NULL) return NULL;
+ int size_needed = WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), NULL, 0, NULL, NULL);
+ char* strTo = new char[ size_needed + 1 ];
+ WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), strTo, size_needed, NULL, NULL);
+ strTo[size_needed] = '\0';
+ return strTo;
+ }
+ // Convert an UTF8 string to a wide Unicode String
+ wchar_t* utf8_decode(const char* decoded)
+ {
+ if (decoded == NULL) return NULL;
+ int size_needed = MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), NULL, 0);
+ wchar_t* wstrTo = new wchar_t[ size_needed + 1 ];
+ MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), wstrTo, size_needed);
+ wstrTo[size_needed] = '\0';
+ return wstrTo;
+ }
+ // Convert a wide Unicode std::wstring to an UTF8 string
+ std::string utf8_encode_s(const std::wstring& encoded) {
+ char* anEncoded = utf8_encode(encoded.c_str());
+ std::string res = std::string(anEncoded);
+ delete [] anEncoded;
+ return res;
+ }
+ // Convert an UTF8 std::string to a wide Unicode std::wstring
+ std::wstring utf8_decode_s(const std::string& decoded) {
+ wchar_t* aDecoded = utf8_decode(decoded.c_str());
+ std::wstring res = std::wstring(aDecoded);
+ delete [] aDecoded;
+ return res;
+ }
+#endif
}
BASICS_EXPORT const char* encode(const wchar_t* decoded);
BASICS_EXPORT std::string encode_s(const wchar_t* decoded);
+#ifdef WIN32
+ BASICS_EXPORT char* utf8_encode(const wchar_t* encoded);
+ BASICS_EXPORT wchar_t* utf8_decode(const char* decoded);
+ BASICS_EXPORT std::string utf8_encode_s(const std::wstring& encoded);
+ BASICS_EXPORT std::wstring utf8_decode_s(const std::string& decoded);
+#endif
+
//! Get predefined GUID
BASICS_EXPORT std::string GetGUID( GUIDtype );
#ifndef WIN32
}
#else
HINSTANCE handle;
- handle = LoadLibrary( impl_name.c_str() );
+#ifdef UNICODE
+ std::wstring libToLoad = Kernel_Utils::utf8_decode_s( impl_name );
+#else
+ std::string libToLoad = impl_name;
+#endif
+ handle = LoadLibrary(libToLoad.c_str() );
if ( !handle )
{
reason="ImplementationNotFound";
INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
)
ADD_DEFINITIONS(${BOOST_DEFINITIONS})
INSTALL(TARGETS DF EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
ADD_EXECUTABLE(testDF testDF.cxx)
-TARGET_LINK_LIBRARIES(testDF DF)
+TARGET_LINK_LIBRARIES(testDF DF SALOMEBasics)
INSTALL(TARGETS testDF DESTINATION ${SALOME_INSTALL_BINS})
FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
#include "DF_Container.hxx"
#include "DF_ChildIterator.hxx"
+#include "Basics_Utils.hxx"
+#include "Basics_DirUtils.hxx"
+
#ifndef WIN32
#include <unistd.h>
#include <sys/time.h>
std::string GetUserName()
{
#ifdef WIN32
- char* pBuff = new char[UNLEN + 1];
+#ifdef UNICODE
+ wchar_t* pBuff = new wchar_t[UNLEN + 1];
+#else
+ char* pBuff = new char[UNLEN + 1];
+#endif
DWORD dwSize = UNLEN + 1;
std::string retVal;
GetUserName ( pBuff, &dwSize );
- std::string theTmpUserName(pBuff,(int)dwSize -1 );
+#ifdef UNICODE
+ std::wstring theTmpUserName(pBuff, (int)dwSize - 1);
+ retVal = Kernel_Utils::utf8_encode_s(theTmpUserName);
+#else
+ std::string theTmpUserName(pBuff, (int)dwSize - 1);
retVal = theTmpUserName;
+#endif
delete [] pBuff;
return retVal;
#else
bool Exists(const std::string thePath)
{
-#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
- if ( GetLastError () != ERROR_FILE_NOT_FOUND ) {
- return false;
- }
- }
-#else
- int status = access ( thePath.c_str() , F_OK );
- if (status != 0) return false;
-#endif
- return true;
+ return Kernel_Utils::IsExists( thePath );
}
INCLUDE_DIRECTORIES(
${HDF5_INCLUDE_DIRS}
${MPI_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
)
FILE(GLOB SalomeHDFPersist_SOURCES_C "${CMAKE_CURRENT_SOURCE_DIR}/HDF*.c")
ADD_DEFINITIONS(${HDF5_DEFINITIONS})
ADD_LIBRARY(SalomeHDFPersist ${SalomeHDFPersist_SOURCES})
-TARGET_LINK_LIBRARIES(SalomeHDFPersist ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${PLATFORM_LIBS})
+TARGET_LINK_LIBRARIES(SalomeHDFPersist ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${PLATFORM_LIBS} SALOMEBasics)
INSTALL(TARGETS SalomeHDFPersist EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
//
#include "HDFOI.hxx"
+#include "Basics_Utils.hxx"
+
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
//============================================================================
bool HDFascii::isASCII(const char* thePath) {
int fd;
+#if defined(WIN32) && defined(UNICODE)
+ const wchar_t * aPath = Kernel_Utils::utf8_decode(thePath);
+ if (!(fd = _wopen(aPath, O_RDONLY))) return false;
+#else
if(!(fd = open(thePath, O_RDONLY))) return false;
+#endif
char* aBuffer = new char[9];
aBuffer[8] = (char)0;
read(fd, aBuffer, 8);
close(fd);
-
bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
-
delete [] aBuffer;
return res;
{
//Find a temporary directory to store a file
std::string aTmpDir;
+#if defined(UNICODE)
+ wchar_t *Tmp_dir = _wgetenv(L"SALOME_TMP_DIR");
+#else
char *Tmp_dir = getenv("SALOME_TMP_DIR");
+#endif
if(Tmp_dir != NULL) {
+#if defined(UNICODE)
+ aTmpDir = Kernel_Utils::utf8_encode_s(Tmp_dir);
+#else
aTmpDir = std::string(Tmp_dir);
+#endif
if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
}
else {
}
#ifdef WIN32
+#if defined(UNICODE)
+ std::wstring aTmpDirToCreate = Kernel_Utils::utf8_decode_s(aTmpDir);
+ std::wstring aDirToCreate = Kernel_Utils::utf8_decode_s(aDir);
+#else
+ std::string aTmpDirToCreate = aTmpDir;
+ std::string aDirToCreate = aDir;
+#endif
//function CreateDirectory create only final directory, but not intermediate
- CreateDirectory(aTmpDir.c_str(), NULL);
- CreateDirectory(aDir.c_str(), NULL);
+ CreateDirectory(aTmpDirToCreate.c_str(), NULL);
+ CreateDirectory(aDirToCreate.c_str(), NULL);
#else
mkdir(aDir.c_str(), 0x1ff);
#endif
bool Exists(const std::string thePath)
{
#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
+#if defined(UNICODE)
+ std::wstring aPathToCheck = Kernel_Utils::utf8_decode_s( thePath );
+#else
+ std::string aPathToCheck = thePath;
+#endif
+ if ( GetFileAttributes ( aPathToCheck.c_str() ) == 0xFFFFFFFF ) {
DWORD errorId = GetLastError ();
if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
return false;
void Move(const std::string& fName, const std::string& fNameDst)
{
#ifdef WIN32
- MoveFileEx (fName.c_str(), fNameDst.c_str(),MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
+#if defined(UNICODE)
+ std::wstring fNameToMove = Kernel_Utils::utf8_decode_s( fName );
+ std::wstring fNameDestination = Kernel_Utils::utf8_decode_s( fNameDst );
+#else
+ std::string fNameToMove = fName;
+ std::string fNameDestination = fNameDst;
+#endif
+ MoveFileEx ( fNameToMove.c_str(), fNameDestination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
#else
- rename(fName.c_str(), fNameDst.c_str());
+ rename( fName.c_str(), fNameDst.c_str() );
#endif
}
#elif defined WIN32
#define SHMEMSIZE 4096
-
+#ifdef UNICODE
+ std::wstring empty = L"";
+#else
+ std::string empty = "";
+#endif
HANDLE hMapObject = CreateFileMapping(
- INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, SHMEMSIZE, "");
+ INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, SHMEMSIZE, empty.c_str() );
if (hMapObject != NULL) {
// Get a pointer to the file-mapped shared memory.
buffer = ( char* ) MapViewOfFile(
#include <map>
#include "utilities.h"
+#include <Basics_Utils.hxx>
+
#ifdef WIN32
# include <process.h>
+# include <windows.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <io.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <wchar.h>
#else
# include <unistd.h>
#endif
ParserComponents _moduleList;
SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
-
+#if defined(WIN32)
+ const wchar_t* w_file = Kernel_Utils::utf8_decode(file);
+ FILE* aFile = _wfopen(w_file, L"r");
+#else
FILE* aFile = fopen(file, "r");
-
+#endif
+
if (aFile != NULL)
{
xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
}
#ifndef WIN32
else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserName();
+#else
+#ifdef UNICODE
+ else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameW();
#else
else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameA();
+#endif
#endif
return aName;
}
{
if(CORBA::is_nil(_corba_impl))
return false;
- std::wstring wtheStudyUrl = std::wstring(theStudyUrl.begin(), theStudyUrl.end());
+ std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
if (!_corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() ) )
return false;
Unexpect aCatch(SalomeException);
MESSAGE("Begin of SALOMEDS_Study_i::Open");
-
std::string aUrl = Kernel_Utils::encode_s(aWUrl);
- bool res = _impl->Open(std::string(aUrl));
+ bool res = _impl->Open( aUrl );
// update desktop title with new study name
//NameChanged();
#ifdef WIN32
#include <windows.h>
static HMODULE _libHandle = 0;
+#ifdef UNICODE
+#define SALOMEDS_LIB_NAME L"SalomeDS.dll"
+#else
#define SALOMEDS_LIB_NAME "SalomeDS.dll"
+#endif
#else
#include <dlfcn.h>
static void* _libHandle = NULL;
#else
aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
#endif
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring awCmd = Kernel_Utils::utf8_decode_s(aCmd);
+ _wsystem( awCmd.c_str() );
+#else
system(aCmd.c_str());
+#endif
// Iterate and move files in the temporary directory
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring awTmpFile = Kernel_Utils::utf8_decode_s(aTmpFile);
+ FILE* fp = _wfopen(awTmpFile.c_str(), L"rb");
+#else
FILE* fp = fopen(aTmpFile.c_str(), "rb");
+#endif
if (!fp) {
URL( anOldName ); // VSR: restore previous url if operation is failed
return false;
#else
aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
#endif
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring awCmd = Kernel_Utils::utf8_decode_s(aCmd);
+ errors = _wsystem(awCmd.c_str());
+#else
errors = system(aCmd.c_str());
+#endif
}
delete []buffer;
// Perform cleanup
#ifdef WIN32
- DeleteFileA(aTmpFile.c_str());
+#ifdef UNICODE
+ std::wstring aTmpFileToDelete = Kernel_Utils::utf8_decode_s(aTmpFile);
+
+#else
+ std::string aTmpFileToDelete = aTmpFile;
+#endif
+ DeleteFile(aTmpFileToDelete.c_str());
#else
unlink(aTmpFile.c_str());
#endif
#ifdef WIN32
- RemoveDirectoryA(aTmpFileDir.c_str());
- RemoveDirectoryA(aStudyTmpDir.c_str());
+#ifdef UNICODE
+ std::wstring aTmpFileDirToDelete = Kernel_Utils::utf8_decode_s( aTmpFileDir );
+ std::wstring aStudyTmpDirToDelete = Kernel_Utils::utf8_decode_s( aStudyTmpDir );
+#else
+ std::string aTmpFileDirToDelete = aTmpFileDir;
+ std::string aStudyTmpDirToDelete = aStudyTmpDir;
+#endif
+ RemoveDirectory( aTmpFileDirToDelete.c_str() );
+ RemoveDirectory( aStudyTmpDirToDelete.c_str() );
#else
rmdir(aTmpFileDir.c_str());
rmdir(aStudyTmpDir.c_str());
//Create a file that will contain a main Study script
std::fstream fp;
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring aConverterFN = Kernel_Utils::utf8_decode_s(aFileName);
+ fp.open(aConverterFN.c_str(), std::ios::out);
+#else
fp.open(aFileName.c_str(), std::ios::out);
+#endif
#ifdef WIN32
bool isOpened = fp.is_open();
aFileName += aScriptName+ std::string(".py");
aSeqOfFileNames.push_back(aFileName);
+#if defined(WIN32) && defined(UNICODE)
+ std::wstring aConverterFN2 = Kernel_Utils::utf8_decode_s(aFileName);
+ fp2.open(aConverterFN2.c_str(), std::ios::out);
+#else
fp2.open(aFileName.c_str(), std::ios::out);
+#endif
#ifdef WIN32
isOpened = fp2.is_open();
#include <iterator>
#include <sstream>
+#include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
+
#include "SALOMEDSImpl_Tool.hxx"
#ifndef WIN32
bool SALOMEDS_Exists(const std::string thePath)
{
-#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
- if ( GetLastError () == ERROR_FILE_NOT_FOUND ) {
- return false;
- }
- }
-#else
- int status = access ( thePath.c_str() , F_OK );
- if (status != 0) return false;
-#endif
- return true;
+ return Kernel_Utils::IsExists( thePath );
}
-
-
-
//============================================================================
// function : GetTempDir
// purpose : Return a temp directory to store created files like "/tmp/sub_dir/"
//============================================================================
std::string SALOMEDSImpl_Tool::GetTmpDir()
{
- //Find a temporary directory to store a file
-
- std::string aTmpDir;
-
- char *Tmp_dir = getenv("SALOME_TMP_DIR");
- if ( Tmp_dir != NULL && SALOMEDS_Exists( Tmp_dir ))
- {
- aTmpDir = Tmp_dir;
-#ifdef WIN32
- if ( aTmpDir.back() != '\\') aTmpDir += '\\';
-#else
- if ( aTmpDir.back() != '/') aTmpDir += '/';
-#endif
- }
- else
- {
-#ifdef WIN32
- aTmpDir = "C:\\";
-#else
- aTmpDir = "/tmp/";
-#endif
- }
-
- srand( (unsigned int)time( NULL ));
- int aRND = 999 + (int) (100000.0*rand() / (RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
- char buffer[127];
- sprintf( buffer, "%d", aRND );
- std::string aSubDir( buffer );
- if ( aSubDir.size() <= 1 ) aSubDir = "123409876";
-
- aTmpDir += aSubDir; //Get RND sub directory
-
- std::string aDir = aTmpDir;
-
- for ( aRND = 0; SALOMEDS_Exists( aDir ); aRND++ )
- {
- sprintf(buffer, "%d", aRND);
- aDir = aTmpDir + buffer; //Build a unique directory name
- }
-
-#ifdef WIN32
- if ( aDir.back() != '\\') aDir += '\\';
-#else
- if ( aDir.back() != '/' ) aDir += '/';
-#endif
-
-
-#ifdef WIN32
- CreateDirectory( aDir.c_str(), NULL );
-#else
- mkdir( aDir.c_str(), 0x1ff );
-#endif
-
- return aDir;
+ return Kernel_Utils::GetTmpDirByEnv("SALOME_TMP_DIR");
}
//============================================================================
if(!SALOMEDS_Exists(aFile)) continue;
#ifdef WIN32
- DeleteFile(aFile.c_str());
+#if defined(UNICODE)
+ std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile);
+#else
+ std::string aFileToDelete = aFile;
+#endif
+ DeleteFile( aFileToDelete.c_str() );
#else
unlink(aFile.c_str());
#endif
if(IsDirDeleted) {
if(SALOMEDS_Exists(aDirName)) {
#ifdef WIN32
- RemoveDirectory(aDirName.c_str());
+#if defined(UNICODE)
+ std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName);
+#else
+ std::string aDirToDelete = aDirName;
+#endif
+ RemoveDirectory(aDirToDelete.c_str());
#else
rmdir(aDirName.c_str());
#endif
handle = dlopen( impl_name.c_str() , RTLD_LAZY | RTLD_GLOBAL ) ;
#else
HINSTANCE handle;
- std::string impl_name = std::string ("lib") + traceKind + std::string(".dll");
- handle = LoadLibrary( impl_name.c_str() );
+ std::string impl_name = std::string ("lib") + traceKind + std::string(".dll");
+ handle = LoadLibraryA( impl_name.c_str() );
#endif
if ( handle )
{
#include "utilities.h"
#include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
#ifndef WIN32
#include <sys/time.h>
bool Exists(const std::string thePath)
{
-#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
- if ( GetLastError () == ERROR_FILE_NOT_FOUND ) {
- return false;
- }
- }
-#else
- int status = access ( thePath.c_str() , F_OK );
- if (status != 0) return false;
-#endif
- return true;
+ return Kernel_Utils::IsExists(thePath);
}
if(!Exists(aFile)) continue;
#ifdef WIN32
- DeleteFile(aFile.c_str());
+#if defined(UNICODE)
+ std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile);
+#else
+ std::string aFileToDelete = aFile;
+#endif
+ DeleteFile(aFileToDelete.c_str());
#else
unlink(aFile.c_str());
#endif
if(IsDirDeleted) {
if(Exists(aDirName)) {
#ifdef WIN32
- RemoveDirectory(aDirName.c_str());
+#if defined(UNICODE)
+ std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName);
+#else
+ std::string aDirToDelete = aDirName;
+#endif
+ RemoveDirectory(aDirToDelete.c_str());
#else
rmdir(aDirName.c_str());
#endif
std::string aFullPath = aTmpDir + theFiles[i];
if(!Exists(aFullPath)) continue;
#ifdef WIN32
+#ifdef UNICODE
+ std::ifstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
std::ifstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
#else
std::ifstream aFile(aFullPath.c_str());
#endif
if ( aNbFiles == 0 ) return (new SALOMEDS::TMPFile);
aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream;
- unsigned char* aBuffer = new unsigned char[aBufferSize];
+ unsigned char* aBuffer = new unsigned char[aBufferSize];
+
if(aBuffer == NULL)
return (new SALOMEDS::TMPFile);
aCurrentPos = 4;
for(i=0; i<aLength; i++) {
- std::ifstream *aFile;
+ std::ifstream *aFile;
if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
std::string aFullPath = aTmpDir + theFiles[i];
if(!Exists(aFullPath)) continue;
#ifdef WIN32
+#ifdef UNICODE
+ aFile = new std::ifstream (Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
aFile = new std::ifstream(aFullPath.c_str(), std::ios::binary);
+#endif
#else
aFile = new std::ifstream(aFullPath.c_str());
#endif
aCurrentPos += 8;
aFile->seekg(0, std::ios::beg);
- aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
+ aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
aFile->close();
delete(aFile);
aCurrentPos += aFileSize[i];
//Get a temporary directory for saving a file
std::string aTmpDir = theToDirectory;
-
unsigned char *aBuffer = (unsigned char*)theStream.NP_data();
if(aBuffer == NULL)
std::string aFullPath = aTmpDir + aFileName;
#ifdef WIN32
+#ifdef UNICODE
+ std::ofstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
#else
std::ofstream aFile(aFullPath.c_str());
#endif
- aFile.write((char *)(aBuffer+aCurrentPos), aFileSize);
+ aFile.write((char *)(aBuffer + aCurrentPos), aFileSize);
aFile.close();
aCurrentPos += aFileSize;
}
void printBacktrace(std::stringstream& txt)
{
typedef USHORT(WINAPI *CaptureStackBackTraceType)(__in ULONG, __in ULONG, __out PVOID*, __out_opt PULONG);
- CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(LoadLibrary("kernel32.dll"), "RtlCaptureStackBackTrace"));
+
+ CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(LoadLibraryA("kernel32.dll"), "RtlCaptureStackBackTrace"));
if (func == NULL)
return;
#include <direct.h>
#include <process.h>
+#include "Basics_Utils.hxx"
+
const char* duplicate( const char *const str ) ;
const char* get_uname( void )
{
- static std::string hostName(4096, 0);
+#ifdef UNICODE
+ std::wstring hostName(4096, 0);
+#else
+ static std::string hostName(4096, 0);
+#endif
static DWORD nSize = hostName.length();
static int res = ::GetComputerNameEx(ComputerNameDnsFullyQualified, &hostName[0], &nSize);
ASSERT( res );
+#ifdef UNICODE
+ static std::string aRes = Kernel_Utils::utf8_encode_s(hostName);
+ return aRes.c_str();
+#else
return hostName.c_str();
+#endif
}
const char* get_adip( void )
const char* const get_pwname( void )
{
- static std::string retVal(4096, 0);
+#ifdef UNICODE
+ std::wstring retVal(4096, 0);
+#else
+ static std::string retVal(4096, 0);
+#endif
static DWORD dwSize = retVal.length() + 1;
static int res = GetUserName( &retVal[0], &dwSize );
ASSERT( res );
+#ifdef UNICODE
+ static std::string aRes = Kernel_Utils::utf8_encode_s(retVal);
+ return aRes.c_str();
+#else
return retVal.c_str();
+#endif
}
PSID getuid() {