Apache HTTPD
apr_app.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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 (which this module kindly
22 * provides to the developer who links to libaprapp-1.lib).
23 * This module becomes the true wmain entry point, and passes
24 * utf-8 reformatted argv and env arrays to the application's
25 * main() function as if nothing happened.
26 *
27 * This module is only compatible with Unicode operating systems.
28 * Mixed (Win9x backwards compatible) binaries should refer instead
29 * to the apr_startup.c module.
30 *
31 * _dbg_malloc/realloc is used in place of the usual API, in order
32 * to convince the MSVCRT that it created these entities. If we
33 * do not create them as _CRT_BLOCK entities, the crt will fault
34 * on an assert. We are not worrying about the crt's locks here,
35 * since we are single threaded [so far].
36 */
37
38#include "apr_general.h"
39#include "ShellAPI.h"
40#include "wchar.h"
41#include "apr_arch_file_io.h"
42#include "assert.h"
43#include "apr_private.h"
44#include "apr_arch_misc.h"
45
46#pragma comment(linker,"/ENTRY:wmainCRTStartup")
47
48extern int main(int argc, const char **argv, const char **env);
49
50int wmain(int argc, const wchar_t **wargv, const wchar_t **wenv)
51{
52 char **argv;
53 char **env;
54 int envc;
55 int i;
56
58
59 envc = 0;
60 while (wenv[envc]) {
61 envc++;
62 }
63
64 /* Initial environment stored as single heap block, but uses
65 * separate heap entry for every environment variable
66 * after first change.
67 */
68 env = apr_malloc_dbg((envc + 1) * sizeof(char *), __FILE__, __LINE__);
69
70 for (i = 0; i < envc; i++) {
73
74 wcount = wcslen(wenv[i]) + 1;
75 envlen = (wcount - 1) * 3 + 1;
76
78
80 }
81
82 env[i] = NULL;
83
84 _environ = env;
85
86 /* MSVCRT will attempt to maintain the wide environment calls
87 * on _putenv(), which is bogus if we've passed a non-ascii
88 * string to _putenv(), since they use MultiByteToWideChar
89 * and breaking the implicit utf-8 assumption we've built.
90 *
91 * Reset _wenviron for good measure.
92 */
93 if (_wenviron) {
95
96 /* There is no need to free _wenviron because MSVCRT
97 * automatically free 'initial' environment block.
98 */
99 }
100
102
103 return main(argc, argv, env);
104}
int wmain(int argc, const wchar_t **wargv, const wchar_t **wenv)
Definition apr_app.c:50
APR Miscellaneous library routines.
apr_size_t size
apr_pool_t int argc
Definition apr_getopt.h:104
char const *const char const *const ** env
const char * argv[3]
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
int main(void)
Definition occhild.c:9
static APR_INLINE void * apr_malloc_dbg(size_t size, const char *filename, int linenumber)
int APR_DECLARE_DATA apr_app_init_complete
Definition start.c:31
int apr_wastrtoastr(char const *const **retarr, wchar_t const *const *arr, int args)
Definition internal.c:40