added wxGet/Set/UnsetEnv() for Unix
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8837 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b855ef7757
commit
8fd0d89b7d
@ -37,6 +37,10 @@ base
|
||||
gtk
|
||||
motif
|
||||
win32
|
||||
base-debug
|
||||
gtk-debug
|
||||
motif-debug
|
||||
win32-debug
|
||||
base-release
|
||||
gtk-release
|
||||
motif-release
|
||||
|
@ -2446,6 +2446,9 @@ AC_CHECK_FUNCS(vfork)
|
||||
dnl check for timegm() used by datetime.cpp
|
||||
AC_CHECK_FUNCS(timegm)
|
||||
|
||||
dnl look for a functiopn to modify the environment
|
||||
AC_CHECK_FUNCS(putenv setenv, break)
|
||||
|
||||
HAVE_SOME_SLEEP_FUNC=0
|
||||
if test "$USE_BEOS" = 1; then
|
||||
dnl BeOS has its own (wonder where did they get it from) sleep() function
|
||||
|
@ -59,7 +59,7 @@ class WXDLLEXPORT wxPoint;
|
||||
// String functions (deprecated, use wxString)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Useful buffer (FIXME VZ: yeah, that is. To be removed!)
|
||||
// Useful buffer (FIXME VZ: To be removed!!!)
|
||||
WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
|
||||
|
||||
// Make a copy of this string using 'new'
|
||||
@ -203,6 +203,20 @@ WXDLLEXPORT long wxGetFreeMemory();
|
||||
// should wxApp::OnFatalException() be called?
|
||||
WXDLLEXPORT bool wxHandleFatalExceptions(bool doit = TRUE);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Environment variables
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// wxGetenv is declared in wxchar.h, but define a wrapper/synonym for it for
|
||||
// consistency with wxSetEnv
|
||||
inline const wxChar *wxGetEnv(const wxString& var) { return wxGetenv(var); }
|
||||
|
||||
// set the env var name to the given value, return TRUE on success
|
||||
WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value);
|
||||
|
||||
// remove the env var from environment
|
||||
inline bool wxUnsetEnv(const wxString& var) { return wxSetEnv(var, NULL); }
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Network and username functions.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -40,7 +40,8 @@
|
||||
//#define TEST_DATETIME
|
||||
//#define TEST_DIR
|
||||
//#define TEST_DLLLOADER
|
||||
#define TEST_EXECUTE
|
||||
#define TEST_ENVIRON
|
||||
//#define TEST_EXECUTE
|
||||
//#define TEST_FILE
|
||||
//#define TEST_FILECONF
|
||||
//#define TEST_HASH
|
||||
@ -283,6 +284,31 @@ static void TestDllLoad()
|
||||
|
||||
#endif // TEST_DLLLOADER
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGet/SetEnv
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef TEST_ENVIRON
|
||||
|
||||
#include <wx/utils.h>
|
||||
|
||||
static void TestEnvironment()
|
||||
{
|
||||
const wxChar *var = _T("wxTestVar");
|
||||
|
||||
puts("*** testing environment access functions ***");
|
||||
|
||||
printf("Initially getenv(%s) = '%s'\n", var, wxGetenv(var));
|
||||
wxSetEnv(var, _T("value for wxTestVar"));
|
||||
printf("After wxSetEnv: getenv(%s) = '%s'\n", var, wxGetenv(var));
|
||||
wxSetEnv(var, _T("another value"));
|
||||
printf("After 2nd wxSetEnv: getenv(%s) = '%s'\n", var, wxGetenv(var));
|
||||
wxUnsetEnv(var);
|
||||
printf("After wxUnsetEnv: getenv(%s) = '%s'\n", var, wxGetenv(var));
|
||||
}
|
||||
|
||||
#endif // TEST_ENVIRON
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxExecute
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -3684,6 +3710,10 @@ int main(int argc, char **argv)
|
||||
TestDllLoad();
|
||||
#endif // TEST_DLLLOADER
|
||||
|
||||
#ifdef TEST_ENVIRON
|
||||
TestEnvironment();
|
||||
#endif // TEST_ENVIRON
|
||||
|
||||
#ifdef TEST_EXECUTE
|
||||
TestExecute();
|
||||
#endif // TEST_EXECUTE
|
||||
|
@ -750,6 +750,12 @@
|
||||
/* Define if you have the nanosleep function. */
|
||||
#undef HAVE_NANOSLEEP
|
||||
|
||||
/* Define if you have the putenv function. */
|
||||
#undef HAVE_PUTENV
|
||||
|
||||
/* Define if you have the setenv function. */
|
||||
#undef HAVE_SETENV
|
||||
|
||||
/* Define if you have the shl_load function. */
|
||||
#undef HAVE_SHL_LOAD
|
||||
|
||||
|
@ -869,6 +869,33 @@ long wxGetFreeMemory()
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// env vars
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxSetEnv(const wxString& variable, const wxChar *value)
|
||||
{
|
||||
#if defined(HAVE_SETENV)
|
||||
return setenv(variable.mb_str(), value ? wxString(value).mb_str().data()
|
||||
: NULL, 1 /* overwrite */) == 0;
|
||||
#elif defined(HAVE_PUTENV)
|
||||
wxString s = variable;
|
||||
if ( value )
|
||||
s << _T('=') << value;
|
||||
|
||||
// transform to ANSI
|
||||
const char *p = s.mb_str();
|
||||
|
||||
// the string will be free()d by libc
|
||||
char *buf = (char *)malloc(strlen(p) + 1);
|
||||
strcpy(buf, p);
|
||||
|
||||
return putenv(buf) == 0;
|
||||
#else // no way to set an env var
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// signal handling
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user