make wxSetEnv compatible with ANSI and Unicode, deprecate passing NULL to it in favour of wxUnsetEnv()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46547 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
531814a7fb
commit
90a77e6484
@ -4686,13 +4686,17 @@ Returns \true if the variable exists, \false otherwise.
|
|||||||
|
|
||||||
\membersection{wxSetEnv}\label{wxsetenv}
|
\membersection{wxSetEnv}\label{wxsetenv}
|
||||||
|
|
||||||
\func{bool}{wxSetEnv}{\param{const wxString\&}{ var}, \param{const wxChar *}{value}}
|
\func{bool}{wxSetEnv}{\param{const wxString\&}{ var}, \param{const wxString\& }{value}}
|
||||||
|
|
||||||
Sets the value of the environment variable {\it var} (adding it if necessary)
|
Sets the value of the environment variable {\it var} (adding it if necessary)
|
||||||
to {\it value}.
|
to {\it value}.
|
||||||
|
|
||||||
Returns \true on success.
|
Returns \true on success.
|
||||||
|
|
||||||
|
\wxheading{See also}
|
||||||
|
|
||||||
|
\helpref{wxUnsetEnv}{wxunsetenv}
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxUnsetEnv}\label{wxunsetenv}
|
\membersection{wxUnsetEnv}\label{wxunsetenv}
|
||||||
|
|
||||||
@ -4703,3 +4707,7 @@ Removes the variable {\it var} from the environment.
|
|||||||
function.
|
function.
|
||||||
|
|
||||||
Returns \true on success.
|
Returns \true on success.
|
||||||
|
|
||||||
|
\wxheading{See also}
|
||||||
|
|
||||||
|
\helpref{wxSetEnv}{wxsetenv}
|
||||||
|
@ -457,10 +457,30 @@ WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true);
|
|||||||
WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value);
|
WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value);
|
||||||
|
|
||||||
// set the env var name to the given value, return true on success
|
// set the env var name to the given value, return true on success
|
||||||
WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxChar *value);
|
WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxString& value);
|
||||||
|
|
||||||
// remove the env var from environment
|
// remove the env var from environment
|
||||||
inline bool wxUnsetEnv(const wxString& var) { return wxSetEnv(var, NULL); }
|
WXDLLIMPEXP_BASE bool wxUnsetEnv(const wxString& var);
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
inline bool wxSetEnv(const wxString& var, const char *value)
|
||||||
|
{ return wxSetEnv(var, wxString(value)); }
|
||||||
|
inline bool wxSetEnv(const wxString& var, const wchar_t *value)
|
||||||
|
{ return wxSetEnv(var, wxString(value)); }
|
||||||
|
template<typename T>
|
||||||
|
inline bool wxSetEnv(const wxString& var, const wxCharTypeBuffer<T>& value)
|
||||||
|
{ return wxSetEnv(var, wxString(value)); }
|
||||||
|
inline bool wxSetEnv(const wxString& var, const wxCStrData& value)
|
||||||
|
{ return wxSetEnv(var, wxString(value)); }
|
||||||
|
|
||||||
|
// this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
|
||||||
|
wxDEPRECATED( inline bool wxSetEnv(const wxString& var, int value) );
|
||||||
|
inline bool wxSetEnv(const wxString& var, int value)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( value == 0, "using non-NULL integer as string?" );
|
||||||
|
return wxUnsetEnv(var);
|
||||||
|
}
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Network and username functions.
|
// Network and username functions.
|
||||||
|
@ -306,7 +306,13 @@ WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the env var name to the given value, return true on success
|
// set the env var name to the given value, return true on success
|
||||||
WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
|
WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxString& value)
|
||||||
|
{
|
||||||
|
// TODO : under classic there is no environement support, under X yes
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WXDLLEXPORT bool wxUnsetEnv(const wxString& var)
|
||||||
{
|
{
|
||||||
// TODO : under classic there is no environement support, under X yes
|
// TODO : under classic there is no environement support, under X yes
|
||||||
return false;
|
return false;
|
||||||
|
@ -96,7 +96,7 @@ bool wxGetEnv(const wxString& var, wxString *value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSetEnv(const wxString& variable, const wxChar *value)
|
static bool wxDoSetEnv(const wxString& variable, const char *value)
|
||||||
{
|
{
|
||||||
wxString s = variable;
|
wxString s = variable;
|
||||||
if ( value )
|
if ( value )
|
||||||
@ -112,6 +112,17 @@ bool wxSetEnv(const wxString& variable, const wxChar *value)
|
|||||||
return putenv(buf) == 0;
|
return putenv(buf) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSetEnv(const wxString& variable, const wxString& value)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, value.mb_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxUnsetEnv(const wxString& variable)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Hostname, username, home directory
|
// Hostname, username, home directory
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -625,8 +625,8 @@ bool wxGetEnv(const wxString& WXUNUSED_IN_WINCE(var),
|
|||||||
#endif // WinCE/32
|
#endif // WinCE/32
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSetEnv(const wxString& WXUNUSED_IN_WINCE(var),
|
bool wxDoSetEnv(const wxString& WXUNUSED_IN_WINCE(var),
|
||||||
const wxChar *WXUNUSED_IN_WINCE(value))
|
const wxChar *WXUNUSED_IN_WINCE(value))
|
||||||
{
|
{
|
||||||
// some compilers have putenv() or _putenv() or _wputenv() but it's better
|
// some compilers have putenv() or _putenv() or _wputenv() but it's better
|
||||||
// to always use Win32 function directly instead of dealing with them
|
// to always use Win32 function directly instead of dealing with them
|
||||||
@ -634,7 +634,7 @@ bool wxSetEnv(const wxString& WXUNUSED_IN_WINCE(var),
|
|||||||
// no environment variables under CE
|
// no environment variables under CE
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
if ( !::SetEnvironmentVariable(var, value) )
|
if ( !::SetEnvironmentVariable(var.wx_str(), value) )
|
||||||
{
|
{
|
||||||
wxLogLastError(_T("SetEnvironmentVariable"));
|
wxLogLastError(_T("SetEnvironmentVariable"));
|
||||||
|
|
||||||
@ -645,6 +645,16 @@ bool wxSetEnv(const wxString& WXUNUSED_IN_WINCE(var),
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSetEnv(const wxString& variable, const wxString& value)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, value.wx_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxUnsetEnv(const wxString& variable)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// process management
|
// process management
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -238,11 +238,10 @@ bool wxGetEnv(const wxString& var, wxString *value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSetEnv(const wxString& variable, const wxChar *value)
|
bool wxSetEnv(const wxString& variable, const char *value)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETENV)
|
#if defined(HAVE_SETENV)
|
||||||
return setenv(variable.mb_str(), value ? wxString(value).mb_str().data()
|
return setenv(variable.mb_str(), value, 1 /* overwrite */) == 0;
|
||||||
: NULL, 1 /* overwrite */) == 0;
|
|
||||||
#elif defined(HAVE_PUTENV)
|
#elif defined(HAVE_PUTENV)
|
||||||
wxString s = variable;
|
wxString s = variable;
|
||||||
if ( value )
|
if ( value )
|
||||||
@ -263,6 +262,16 @@ bool wxSetEnv(const wxString& variable, const wxChar *value)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSetEnv(const wxString& variable, const wxString& value)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, value.mb_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxUnsetEnv(const wxString& variable)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void wxMilliSleep(
|
void wxMilliSleep(
|
||||||
unsigned long ulMilliseconds
|
unsigned long ulMilliseconds
|
||||||
)
|
)
|
||||||
|
@ -127,6 +127,11 @@ bool wxSetEnv(const wxString& var, const wxChar *value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxUnsetEnv(const wxString& var)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// process management
|
// process management
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -1064,13 +1064,10 @@ bool wxGetEnv(const wxString& var, wxString *value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSetEnv(const wxString& variable, const wxChar *value)
|
static bool wxDoSetEnv(const wxString& variable, const char *value)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SETENV)
|
#if defined(HAVE_SETENV)
|
||||||
return setenv(variable.mb_str(),
|
return setenv(variable.mb_str(), value, 1 /* overwrite */) == 0;
|
||||||
value ? (const char *)wxString(value).mb_str()
|
|
||||||
: NULL,
|
|
||||||
1 /* overwrite */) == 0;
|
|
||||||
#elif defined(HAVE_PUTENV)
|
#elif defined(HAVE_PUTENV)
|
||||||
wxString s = variable;
|
wxString s = variable;
|
||||||
if ( value )
|
if ( value )
|
||||||
@ -1089,6 +1086,16 @@ bool wxSetEnv(const wxString& variable, const wxChar *value)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSetEnv(const wxString& variable, const wxString& value)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, value.mb_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxUnsetEnv(const wxString& variable)
|
||||||
|
{
|
||||||
|
return wxDoSetEnv(variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// signal handling
|
// signal handling
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user