mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0027198: OSD_Environment - use wide characters API on Windows
This commit is contained in:
parent
5df609e75d
commit
8582eb08cc
@ -23,6 +23,7 @@
|
|||||||
#include <Standard_Mutex.hxx>
|
#include <Standard_Mutex.hxx>
|
||||||
#include <Standard_NullObject.hxx>
|
#include <Standard_NullObject.hxx>
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
#include <NCollection_UtfString.hxx>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -239,7 +240,11 @@ Standard_Integer OSD_Environment::Error() const
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#pragma warning( disable : 4700 )
|
#include <NCollection_UtfString.hxx>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning( disable : 4700 )
|
||||||
|
#endif
|
||||||
|
|
||||||
static void __fastcall _set_error ( OSD_Error&, DWORD );
|
static void __fastcall _set_error ( OSD_Error&, DWORD );
|
||||||
|
|
||||||
@ -269,41 +274,39 @@ void OSD_Environment :: SetValue ( const TCollection_AsciiString& Value ) {
|
|||||||
|
|
||||||
} // end OSD_Environment :: SetValue
|
} // end OSD_Environment :: SetValue
|
||||||
|
|
||||||
TCollection_AsciiString OSD_Environment :: Value () {
|
TCollection_AsciiString OSD_Environment::Value()
|
||||||
|
{
|
||||||
|
myValue.Clear();
|
||||||
|
|
||||||
Standard_PCharacter pBuff=0;
|
SetLastError (ERROR_SUCCESS);
|
||||||
DWORD dwSize = 0;
|
wchar_t* anEnvVal = NULL;
|
||||||
char* envVal = NULL;
|
NCollection_UtfWideString aNameWide (myName.ToCString());
|
||||||
|
DWORD aSize = GetEnvironmentVariableW (aNameWide.ToCString(), NULL, 0);
|
||||||
|
if ((aSize == 0 && GetLastError() != ERROR_SUCCESS)
|
||||||
|
|| (anEnvVal = _wgetenv (aNameWide.ToCString())) == NULL)
|
||||||
|
{
|
||||||
|
_set_error (myError, ERROR_ENVVAR_NOT_FOUND);
|
||||||
|
return myValue;
|
||||||
|
}
|
||||||
|
|
||||||
myValue.Clear ();
|
NCollection_Utf8String aValue;
|
||||||
|
if (anEnvVal != NULL)
|
||||||
SetLastError ( ERROR_SUCCESS );
|
{
|
||||||
dwSize = GetEnvironmentVariable ( myName.ToCString (), pBuff, dwSize );
|
aValue.FromUnicode (anEnvVal);
|
||||||
|
}
|
||||||
if ( ( dwSize == 0 && GetLastError () != ERROR_SUCCESS ) ||
|
else
|
||||||
( envVal = getenv ( myName.ToCString () ) ) == NULL
|
{
|
||||||
)
|
aSize += 1; // NULL-terminator
|
||||||
|
wchar_t* aBuff = new wchar_t[aSize];
|
||||||
_set_error ( myError, ERROR_ENVVAR_NOT_FOUND );
|
GetEnvironmentVariableW (aNameWide.ToCString(), aBuff, aSize);
|
||||||
|
aBuff[aSize - 1] = L'\0';
|
||||||
else if ( envVal != NULL )
|
aValue.FromUnicode (aBuff);
|
||||||
|
delete[] aBuff;
|
||||||
myValue = envVal;
|
Reset();
|
||||||
|
}
|
||||||
else {
|
myValue = aValue.ToCString();
|
||||||
|
return myValue;
|
||||||
++dwSize;
|
}
|
||||||
pBuff = new Standard_Character[ dwSize ];
|
|
||||||
GetEnvironmentVariable ( (char *)myName.ToCString (), pBuff, dwSize );
|
|
||||||
myValue = pBuff;
|
|
||||||
delete [] pBuff;
|
|
||||||
Reset ();
|
|
||||||
|
|
||||||
} // end else
|
|
||||||
|
|
||||||
return myValue;
|
|
||||||
|
|
||||||
} // end OSD_Environment :: Value
|
|
||||||
|
|
||||||
void OSD_Environment :: SetName ( const TCollection_AsciiString& name ) {
|
void OSD_Environment :: SetName ( const TCollection_AsciiString& name ) {
|
||||||
|
|
||||||
@ -317,25 +320,17 @@ TCollection_AsciiString OSD_Environment :: Name () const {
|
|||||||
|
|
||||||
} // end OSD_Environment :: Name
|
} // end OSD_Environment :: Name
|
||||||
|
|
||||||
void OSD_Environment :: Build () {
|
void OSD_Environment::Build()
|
||||||
|
{
|
||||||
|
NCollection_Utf8String aSetVariable = NCollection_Utf8String(myName.ToCString()) + "=" + myValue.ToCString();
|
||||||
|
_wputenv (aSetVariable.ToUtfWide().ToCString());
|
||||||
|
}
|
||||||
|
|
||||||
TCollection_AsciiString str;
|
void OSD_Environment::Remove()
|
||||||
|
{
|
||||||
str = myName + TEXT( "=" ) + myValue;
|
NCollection_Utf8String aSetVariable = NCollection_Utf8String(myName.ToCString()) + "=";
|
||||||
|
_wputenv (aSetVariable.ToUtfWide().ToCString());
|
||||||
_putenv (str.ToCString());
|
}
|
||||||
|
|
||||||
} // end OSD_Environment :: Build
|
|
||||||
|
|
||||||
void OSD_Environment :: Remove () {
|
|
||||||
|
|
||||||
TCollection_AsciiString str;
|
|
||||||
|
|
||||||
str = myName + TEXT( "=" );
|
|
||||||
|
|
||||||
_putenv (str.ToCString());
|
|
||||||
|
|
||||||
} // end OSD_Environment :: Remove
|
|
||||||
|
|
||||||
Standard_Boolean OSD_Environment :: Failed () const {
|
Standard_Boolean OSD_Environment :: Failed () const {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user