wxProcess *process)
{
// for the sync execution, we return -1 to indicate failure, but for async
- // cse we return 0 which is never a valid PID
- long errorRetCode = sync ? -1 : 0;
+ // case we return 0 which is never a valid PID
+ //
+ // we define this as a macro, not a variable, to avoid compiler warnings
+ // about "ERROR_RETURN_CODE value may be clobbered by fork()"
+ #define ERROR_RETURN_CODE ((sync) ? -1 : 0)
- wxCHECK_MSG( *argv, errorRetCode, wxT("can't exec empty command") );
+ wxCHECK_MSG( *argv, ERROR_RETURN_CODE, wxT("can't exec empty command") );
#if wxUSE_UNICODE
int mb_argc = 0;
ARGS_CLEANUP;
- return errorRetCode;
+ return ERROR_RETURN_CODE;
}
#endif // wxUSE_GUI
ARGS_CLEANUP;
- return errorRetCode;
+ return ERROR_RETURN_CODE;
}
}
ARGS_CLEANUP;
- return errorRetCode;
+ return ERROR_RETURN_CODE;
}
else if ( pid == 0 ) // we're in child
{
#endif
}
+#undef ERROR_RETURN_CODE
#undef ARGS_CLEANUP
// ----------------------------------------------------------------------------
const wxChar* wxGetHomeDir( wxString *home )
{
*home = wxGetUserHome( wxString() );
+ wxString tmp;
if ( home->IsEmpty() )
*home = wxT("/");
-
+#ifdef __VMS
+ tmp = *home;
+ if ( tmp.Last() != wxT(']'))
+ if ( tmp.Last() != wxT('/')) *home << wxT('/');
+#endif
return home->c_str();
}
return -1;
}
+// ----------------------------------------------------------------------------
+// env vars
+// ----------------------------------------------------------------------------
+
+bool wxGetEnv(const wxString& var, wxString *value)
+{
+ // wxGetenv is defined as getenv()
+ wxChar *p = wxGetenv(var);
+ if ( !p )
+ return FALSE;
+
+ if ( value )
+ {
+ *value = p;
+ }
+
+ return TRUE;
+}
+
+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
// ----------------------------------------------------------------------------