diff options
author | William A. Rowe Jr <wrowe@apache.org> | 2011-04-14 07:21:39 +0000 |
---|---|---|
committer | William A. Rowe Jr <wrowe@apache.org> | 2011-04-14 07:21:39 +0000 |
commit | fe174e97a0640eefb50b7651aa3064740ee20138 (patch) | |
tree | faece5b42a9f951f2e83bcda164d45131cfe5f7f /misc | |
parent | 72dcb0cdd8e7835b96a4af39cbbaadf145067a3b (diff) | |
download | apr-fe174e97a0640eefb50b7651aa3064740ee20138.tar.gz |
Fix VC10 release build running on Windows7/Server 2008
Submitted by: Steve Hay <SteveHay planit.com>
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1092025 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/win32/start.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/misc/win32/start.c b/misc/win32/start.c index 22820e8e5..eb77d4a4d 100644 --- a/misc/win32/start.c +++ b/misc/win32/start.c @@ -45,7 +45,9 @@ static int warrsztoastr(const char * const * *retarr, apr_size_t totlen; apr_size_t newlen; apr_size_t wsize; - char **newarr; + char **env; + char *pstrs; + char *strs; int arg; if (args < 0) { @@ -55,37 +57,40 @@ static int warrsztoastr(const char * const * *retarr, } wsize = 1 + wch - arrsz; - newarr = apr_malloc_dbg((args + 1) * sizeof(char *), - __FILE__, __LINE__); - - /* This is a safe max allocation, we will realloc after - * processing and return the excess to the free store. + /* This is a safe max allocation, we will alloc each + * string exactly after processing and return this + * temporary buffer to the free store. * 3 ucs bytes hold any single wchar_t value (16 bits) * 4 ucs bytes will hold a wchar_t pair value (20 bits) */ newlen = totlen = wsize * 3 + 1; - newarr[0] = apr_malloc_dbg(newlen * sizeof(char), - __FILE__, __LINE__); + pstrs = strs = apr_malloc_dbg(newlen * sizeof(char), + __FILE__, __LINE__); - (void)apr_conv_ucs2_to_utf8(arrsz, &wsize, - newarr[0], &newlen); + (void)apr_conv_ucs2_to_utf8(arrsz, &wsize, strs, &newlen); assert(newlen && !wsize); - /* Return to the free store if the heap realloc is the least bit optimized - */ - newarr[0] = apr_realloc_dbg(newarr[0], totlen - newlen, - __FILE__, __LINE__); - for (arg = 1; arg < args; ++arg) { - newarr[arg] = newarr[arg - 1] + 2; - while (*(newarr[arg]++)) { - /* continue */; - } + *retarr = env = apr_malloc_dbg((args + 1) * sizeof(char*), + __FILE__, __LINE__); + for (arg = 0; arg < args; ++arg) { + char* p = pstrs; + int len = 0; + while (*p++) + ++len; + len += 1; + + *env = apr_malloc_dbg(len * sizeof(char), + __FILE__, __LINE__); + memcpy(*env, pstrs, len * sizeof(char)); + + pstrs += len; + ++env; } - newarr[arg] = NULL; + *env = NULL; + free(strs); - *retarr = newarr; return args; } #endif |