wrowe 02/01/29 21:25:53
Modified: misc/win32 apr_app.c
Log:
Final tests still required, but here goes the basic concept. The init
will never run more than once [no test is needed in the wmain() stub,
only for callers into apr_app_main().]
So the NT-only [WinCE, etc] builder can depend upon the apr_app.dsp's
apr_app.lib to stub wmain(), or the Win9x+NT builder can simply stub
in apr_app_main(). Since authors are likely to do the last step always,
they needed this interlock to determine that apr_app_main() activity
is already complete.
Revision Changes Path
1.7 +31 -0 apr/misc/win32/apr_app.c
Index: apr_app.c
===================================================================
RCS file: /home/cvs/apr/misc/win32/apr_app.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apr_app.c 30 Jan 2002 03:15:32 -0000 1.6
+++ apr_app.c 30 Jan 2002 05:25:53 -0000 1.7
@@ -143,6 +143,8 @@
#ifdef APR_APP
+extern int APR_DECLARE_DATA apr_app_init_complete;
+
extern int main(int argc, char **argv, char **env);
int wmain(int argc, wchar_t **wargv, wchar_t **wenv)
@@ -172,11 +174,15 @@
free(wenv);
}
+ apr_app_init_complete = 1;
+
return main(argc, argv, env);
}
#else
+int APR_DECLARE_DATA apr_app_init_complete = 0;
+
static int warrsztoastr(char ***retarr, wchar_t *arrsz, int args)
{
apr_wchar_t *wch;
@@ -238,6 +244,11 @@
apr_wchar_t **wstrs;
apr_wchar_t *sysstr;
int wstrc;
+ int dupenv;
+
+ if (apr_app_init_complete) {
+ return APR_SUCCESS;
+ }
sysstr = GetCommandLineW();
if (sysstr) {
@@ -249,6 +260,26 @@
}
sysstr = GetEnvironmentStringsW();
+ dupenv = warrsztoastr(env, sysstr, -1);
+
+ _environ = _malloc_dbg((dupenv + 1) * sizeof (char *),
+ _CRT_BLOCK, __FILE__, __LINE__ );
+ memcpy(_environ, env, (dupenv + 1) * sizeof (char *));
+
+ /* MSVCRT will attempt to maintain the wide environment calls
+ * on _putenv(), which is bogus if we've passed a non-ascii
+ * string to _putenv(), since they use MultiByteToWideChar
+ * and breaking the implicit utf-8 assumption we've built.
+ *
+ * Reset _wenviron for good measure.
+ */
+ if (_wenviron) {
+ apr_wchar_t **wenv = _wenviron;
+ _wenviron = NULL;
+ free(wenv);
+ }
+
+ apr_app_init_complete = 1;
}
#endif
return APR_SUCCESS;