Alien-uv
view release on metacpan or search on metacpan
libuv/src/win/process.c view on Meta::CPAN
for (arg = args; *arg; arg++) {
DWORD arg_len;
arg_len = MultiByteToWideChar(CP_UTF8,
0,
*arg,
-1,
NULL,
0);
if (arg_len == 0) {
return GetLastError();
}
dst_len += arg_len;
if (arg_len > temp_buffer_len)
temp_buffer_len = arg_len;
arg_count++;
}
/* Adjust for potential quotes. Also assume the worst-case scenario that
* every character needs escaping, so we need twice as much space. */
dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */
dst = (WCHAR*) uv__malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
}
/* Allocate temporary working buffer. */
temp_buffer = (WCHAR*) uv__malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
}
pos = dst;
for (arg = args; *arg; arg++) {
DWORD arg_len;
/* Convert argument to wide char. */
arg_len = MultiByteToWideChar(CP_UTF8,
0,
*arg,
-1,
temp_buffer,
(int) (dst + dst_len - pos));
if (arg_len == 0) {
err = GetLastError();
goto error;
}
if (verbatim_arguments) {
/* Copy verbatim. */
wcscpy(pos, temp_buffer);
pos += arg_len - 1;
} else {
/* Quote/escape, if needed. */
pos = quote_cmd_arg(temp_buffer, pos);
}
*pos++ = *(arg + 1) ? L' ' : L'\0';
}
uv__free(temp_buffer);
*dst_ptr = dst;
return 0;
error:
uv__free(dst);
uv__free(temp_buffer);
return err;
}
int env_strncmp(const wchar_t* a, int na, const wchar_t* b) {
wchar_t* a_eq;
wchar_t* b_eq;
wchar_t* A;
wchar_t* B;
int nb;
int r;
if (na < 0) {
a_eq = wcschr(a, L'=');
assert(a_eq);
na = (int)(long)(a_eq - a);
} else {
na--;
}
b_eq = wcschr(b, L'=');
assert(b_eq);
nb = b_eq - b;
A = alloca((na+1) * sizeof(wchar_t));
B = alloca((nb+1) * sizeof(wchar_t));
r = LCMapStringW(LOCALE_INVARIANT, LCMAP_UPPERCASE, a, na, A, na);
assert(r==na);
A[na] = L'\0';
r = LCMapStringW(LOCALE_INVARIANT, LCMAP_UPPERCASE, b, nb, B, nb);
assert(r==nb);
B[nb] = L'\0';
while (1) {
wchar_t AA = *A++;
wchar_t BB = *B++;
if (AA < BB) {
return -1;
} else if (AA > BB) {
return 1;
} else if (!AA && !BB) {
return 0;
}
}
}
( run in 1.826 second using v1.01-cache-2.11-cpan-e1769b4cff6 )