summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2011-04-14 07:22:06 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2011-04-14 07:22:06 +0000
commitc5b2242dff53fc23fa24bddda28bfd9f067535a8 (patch)
tree1baf27d9f94bccbffc4b64c9209a4d92b20d7d77 /misc
parent8c4c815481169d9eddda2a9d5ccd078d0b9f584f (diff)
downloadlibapr-c5b2242dff53fc23fa24bddda28bfd9f067535a8.tar.gz
Fix VC10 release build running on Windows7/Server 2008
Submitted by: Steve Hay <SteveHay planit.com> Forward ports: 1092025 git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1092026 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r--misc/win32/start.c47
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