~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/misc/win32/apr_app.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
/* Usage Notes:
 
18
 *
 
19
 *   this module, and the misc/win32/utf8.c modules must be 
 
20
 *   compiled APR_EXPORT_STATIC and linked to an application with
 
21
 *   the /entry:wmainCRTStartup flag.  This module becomes the true
 
22
 *   wmain entry point, and passes utf-8 reformatted argv and env
 
23
 *   arrays to the application's main function.
 
24
 *
 
25
 *   This module is only compatible with Unicode-only executables.
 
26
 *   Mixed (Win9x backwards compatible) binaries should refer instead
 
27
 *   to the apr_startup.c module.
 
28
 *
 
29
 *   _dbg_malloc/realloc is used in place of the usual API, in order
 
30
 *   to convince the MSVCRT that they created these entities.  If we
 
31
 *   do not create them as _CRT_BLOCK entities, the crt will fault
 
32
 *   on an assert.  We are not worrying about the crt's locks here, 
 
33
 *   since we are single threaded [so far].
 
34
 */
 
35
 
 
36
#include "apr_general.h"
 
37
#include "ShellAPI.h"
 
38
#include "crtdbg.h"
 
39
#include "wchar.h"
 
40
#include "apr_arch_file_io.h"
 
41
#include "assert.h"
 
42
#include "apr_private.h"
 
43
#include "apr_arch_misc.h"
 
44
 
 
45
/* This symbol is _private_, although it must be exported.
 
46
 */
 
47
 
 
48
extern int main(int argc, const char **argv, const char **env);
 
49
 
 
50
int wmain(int argc, const wchar_t **wargv, const wchar_t **wenv)
 
51
{
 
52
    char **argv;
 
53
    char **env;
 
54
    int dupenv;
 
55
 
 
56
    (void)apr_wastrtoastr(&argv, wargv, argc);
 
57
 
 
58
    dupenv = apr_wastrtoastr(&env, wenv, -1);
 
59
 
 
60
    _environ = _malloc_dbg((dupenv + 1) * sizeof (char *), 
 
61
                           _CRT_BLOCK, __FILE__, __LINE__ );
 
62
    memcpy(_environ, env, (dupenv + 1) * sizeof (char *));
 
63
 
 
64
    /* MSVCRT will attempt to maintain the wide environment calls
 
65
     * on _putenv(), which is bogus if we've passed a non-ascii
 
66
     * string to _putenv(), since they use MultiByteToWideChar
 
67
     * and breaking the implicit utf-8 assumption we've built.
 
68
     *
 
69
     * Reset _wenviron for good measure.
 
70
     */
 
71
    if (_wenviron) {
 
72
        wenv = _wenviron;
 
73
        _wenviron = NULL;
 
74
        free((wchar_t **)wenv);
 
75
    }
 
76
 
 
77
    apr_app_init_complete = 1;
 
78
 
 
79
    return main(argc, argv, env);
 
80
}