* dcrt0.cc (initial_env): Only use local buffer "buf" if DEBUGGING is
enabled. Replace calls to GetEnvironmentVariable by calls to GetEnvironmentVariableA for clarity. Call GetEnvironmentVariableA with NULL buffer. (cygbench): Ditto, drop local buffer. * environ.cc (getearly): Call GetEnvironmentVariableA. (environ_init): Retrieve unicode environment and convert to current codepage locally. (getwinenveq): Ditto. * exceptions.cc (try_to_debug): Accommodate new sys_mbstowcs calling convention. * fhandler_clipboard.cc (set_clipboard): Call sys_mbstowcs to retrieve required buffer length. * fork.cc (frok::child): Call GetEnvironmentVariableA. * miscfuncs.cc: Accommodate changed arguments in calls to sys_mbstowcs. * sec_auth.cc: Ditto. * strfuncs.cc (sys_wcstombs_alloc): Fix formatting. (sys_mbstowcs): Change arguments to allow specifying a source string length. (sys_mbstowcs_alloc): Ditto. * uinfo.cc (cygheap_user::ontherange): Accommodate changed arguments in calls to sys_mbstowcs. * winsup.h (sys_mbstowcs): Adjust declaration. (sys_mbstowcs_alloc): Ditto.
This commit is contained in:
parent
ff42f5b1e3
commit
5ab0b5cf52
|
@ -1,3 +1,30 @@
|
||||||
|
2008-02-25 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* dcrt0.cc (initial_env): Only use local buffer "buf" if DEBUGGING is
|
||||||
|
enabled. Replace calls to GetEnvironmentVariable by calls to
|
||||||
|
GetEnvironmentVariableA for clarity. Call GetEnvironmentVariableA
|
||||||
|
with NULL buffer.
|
||||||
|
(cygbench): Ditto, drop local buffer.
|
||||||
|
* environ.cc (getearly): Call GetEnvironmentVariableA.
|
||||||
|
(environ_init): Retrieve unicode environment and convert to current
|
||||||
|
codepage locally.
|
||||||
|
(getwinenveq): Ditto.
|
||||||
|
* exceptions.cc (try_to_debug): Accommodate new sys_mbstowcs calling
|
||||||
|
convention.
|
||||||
|
* fhandler_clipboard.cc (set_clipboard): Call sys_mbstowcs to retrieve
|
||||||
|
required buffer length.
|
||||||
|
* fork.cc (frok::child): Call GetEnvironmentVariableA.
|
||||||
|
* miscfuncs.cc: Accommodate changed arguments in calls to sys_mbstowcs.
|
||||||
|
* sec_auth.cc: Ditto.
|
||||||
|
* strfuncs.cc (sys_wcstombs_alloc): Fix formatting.
|
||||||
|
(sys_mbstowcs): Change arguments to allow specifying a source string
|
||||||
|
length.
|
||||||
|
(sys_mbstowcs_alloc): Ditto.
|
||||||
|
* uinfo.cc (cygheap_user::ontherange): Accommodate changed arguments in
|
||||||
|
calls to sys_mbstowcs.
|
||||||
|
* winsup.h (sys_mbstowcs): Adjust declaration.
|
||||||
|
(sys_mbstowcs_alloc): Ditto.
|
||||||
|
|
||||||
2008-02-20 Corinna Vinschen <corinna@vinschen.de>
|
2008-02-20 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* path.cc (cwdstuff::set): Revert error handling change in case
|
* path.cc (cwdstuff::set): Revert error handling change in case
|
||||||
|
|
|
@ -532,14 +532,14 @@ break_here ()
|
||||||
static void
|
static void
|
||||||
initial_env ()
|
initial_env ()
|
||||||
{
|
{
|
||||||
char buf[NT_MAX_PATH];
|
if (GetEnvironmentVariableA ("CYGWIN_TESTING", NULL, 0))
|
||||||
if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1))
|
|
||||||
_cygwin_testing = 1;
|
_cygwin_testing = 1;
|
||||||
|
|
||||||
#ifdef DEBUGGING
|
#ifdef DEBUGGING
|
||||||
|
char buf[NT_MAX_PATH];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf) - 1))
|
if (GetEnvironmentVariableA ("CYGWIN_SLEEP", buf, sizeof (buf) - 1))
|
||||||
{
|
{
|
||||||
DWORD ms = atoi (buf);
|
DWORD ms = atoi (buf);
|
||||||
console_printf ("Sleeping %d, pid %u %P\n", ms, GetCurrentProcessId ());
|
console_printf ("Sleeping %d, pid %u %P\n", ms, GetCurrentProcessId ());
|
||||||
|
@ -547,7 +547,7 @@ initial_env ()
|
||||||
if (!strace.active () && !dynamically_loaded)
|
if (!strace.active () && !dynamically_loaded)
|
||||||
strace.hello ();
|
strace.hello ();
|
||||||
}
|
}
|
||||||
if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
|
if (GetEnvironmentVariableA ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
|
||||||
{
|
{
|
||||||
char buf1[NT_MAX_PATH];
|
char buf1[NT_MAX_PATH];
|
||||||
len = GetModuleFileName (NULL, buf1, NT_MAX_PATH);
|
len = GetModuleFileName (NULL, buf1, NT_MAX_PATH);
|
||||||
|
@ -1141,8 +1141,7 @@ multiple_cygwin_problem (const char *what, unsigned magic_version, unsigned vers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[1024];
|
if (GetEnvironmentVariableA ("CYGWIN_MISMATCH_OK", NULL, 0))
|
||||||
if (GetEnvironmentVariable ("CYGWIN_MISMATCH_OK", buf, sizeof (buf)))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (CYGWIN_VERSION_MAGIC_VERSION (magic_version) == version)
|
if (CYGWIN_VERSION_MAGIC_VERSION (magic_version) == version)
|
||||||
|
@ -1162,8 +1161,7 @@ are unable to find another cygwin DLL.",
|
||||||
void __stdcall
|
void __stdcall
|
||||||
cygbench (const char *s)
|
cygbench (const char *s)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
if (GetEnvironmentVariableA ("CYGWIN_BENCH", NULL, 0))
|
||||||
if (GetEnvironmentVariable ("CYGWIN_BENCH", buf, sizeof (buf)))
|
|
||||||
small_printf ("%05d ***** %s : %10d\n", GetCurrentProcessId (), s, strace.microseconds ());
|
small_printf ("%05d ***** %s : %10d\n", GetCurrentProcessId (), s, strace.microseconds ());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,7 @@ details. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/cygwin.h>
|
#include <sys/cygwin.h>
|
||||||
|
@ -252,9 +253,9 @@ getearly (const char * name, int *)
|
||||||
if (strncasematch (name, *ptr, len) && (*ptr)[len] == '=')
|
if (strncasematch (name, *ptr, len) && (*ptr)[len] == '=')
|
||||||
return *ptr + len + 1;
|
return *ptr + len + 1;
|
||||||
}
|
}
|
||||||
else if ((len = GetEnvironmentVariable (name, NULL, 0))
|
else if ((len = GetEnvironmentVariableA (name, NULL, 0))
|
||||||
&& (ret = (char *) cmalloc_abort (HEAP_2_STR, len))
|
&& (ret = (char *) cmalloc_abort (HEAP_2_STR, len))
|
||||||
&& GetEnvironmentVariable (name, ret, len))
|
&& GetEnvironmentVariableA (name, ret, len))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -730,7 +731,7 @@ regopt (const char *name)
|
||||||
void
|
void
|
||||||
environ_init (char **envp, int envc)
|
environ_init (char **envp, int envc)
|
||||||
{
|
{
|
||||||
char *rawenv;
|
PWCHAR rawenv, w;
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
char *newp;
|
char *newp;
|
||||||
|
@ -781,21 +782,31 @@ environ_init (char **envp, int envc)
|
||||||
/* Allocate space for environment + trailing NULL + CYGWIN env. */
|
/* Allocate space for environment + trailing NULL + CYGWIN env. */
|
||||||
lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *));
|
lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *));
|
||||||
|
|
||||||
rawenv = GetEnvironmentStrings ();
|
/* We need the CYGWIN variable content before we can loop through
|
||||||
|
the whole environment, so that the wide-char to multibyte conversion
|
||||||
|
can be done according to the "codepage" setting. */
|
||||||
|
if ((i = GetEnvironmentVariableA ("CYGWIN", NULL, 0)))
|
||||||
|
{
|
||||||
|
char *buf = (char *) alloca (i);
|
||||||
|
GetEnvironmentVariableA ("CYGWIN", buf, i);
|
||||||
|
parse_options (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
rawenv = GetEnvironmentStringsW ();
|
||||||
if (!rawenv)
|
if (!rawenv)
|
||||||
{
|
{
|
||||||
system_printf ("GetEnvironmentStrings returned NULL, %E");
|
system_printf ("GetEnvironmentStrings returned NULL, %E");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug_printf ("GetEnvironmentStrings returned %p - \"%s\"", rawenv, rawenv);
|
debug_printf ("GetEnvironmentStrings returned %p", rawenv);
|
||||||
|
|
||||||
/* Current directory information is recorded as variables of the
|
/* Current directory information is recorded as variables of the
|
||||||
form "=X:=X:\foo\bar; these must be changed into something legal
|
form "=X:=X:\foo\bar; these must be changed into something legal
|
||||||
(we could just ignore them but maybe an application will
|
(we could just ignore them but maybe an application will
|
||||||
eventually want to use them). */
|
eventually want to use them). */
|
||||||
for (i = 0, p = rawenv; *p != '\0'; p = strchr (p, '\0') + 1, i++)
|
for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++)
|
||||||
{
|
{
|
||||||
newp = strdup (p);
|
sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w);
|
||||||
if (i >= envc)
|
if (i >= envc)
|
||||||
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
|
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
|
||||||
envp[i] = newp;
|
envp[i] = newp;
|
||||||
|
@ -816,7 +827,7 @@ environ_init (char **envp, int envc)
|
||||||
if (!sawTERM)
|
if (!sawTERM)
|
||||||
envp[i++] = strdup (cygterm);
|
envp[i++] = strdup (cygterm);
|
||||||
envp[i] = NULL;
|
envp[i] = NULL;
|
||||||
FreeEnvironmentStrings (rawenv);
|
FreeEnvironmentStringsW (rawenv);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
findenv_func = (char * (*)(const char*, int*)) my_findenv;
|
findenv_func = (char * (*)(const char*, int*)) my_findenv;
|
||||||
|
@ -848,14 +859,14 @@ env_sort (const void *a, const void *b)
|
||||||
char * __stdcall
|
char * __stdcall
|
||||||
getwinenveq (const char *name, size_t namelen, int x)
|
getwinenveq (const char *name, size_t namelen, int x)
|
||||||
{
|
{
|
||||||
char dum[1];
|
WCHAR name0[namelen - 1];
|
||||||
char name0[namelen - 1];
|
WCHAR valbuf[32768]; /* Max size of an env.var including trailing '\0'. */
|
||||||
memcpy (name0, name, namelen - 1);
|
|
||||||
name0[namelen - 1] = '\0';
|
name0[sys_mbstowcs (name0, sizeof name0, name, namelen - 1)] = L'\0';
|
||||||
int totlen = GetEnvironmentVariable (name0, dum, 0);
|
int totlen = GetEnvironmentVariableW (name0, valbuf, 32768);
|
||||||
if (totlen > 0)
|
if (totlen > 0)
|
||||||
{
|
{
|
||||||
totlen++;
|
totlen = sys_wcstombs (NULL, 0, valbuf);
|
||||||
if (x == HEAP_1_STR)
|
if (x == HEAP_1_STR)
|
||||||
totlen += namelen;
|
totlen += namelen;
|
||||||
else
|
else
|
||||||
|
@ -863,15 +874,10 @@ getwinenveq (const char *name, size_t namelen, int x)
|
||||||
char *p = (char *) cmalloc_abort ((cygheap_types) x, totlen);
|
char *p = (char *) cmalloc_abort ((cygheap_types) x, totlen);
|
||||||
if (namelen)
|
if (namelen)
|
||||||
strcpy (p, name);
|
strcpy (p, name);
|
||||||
if (GetEnvironmentVariable (name0, p + namelen, totlen))
|
sys_wcstombs (p + namelen, totlen, valbuf);
|
||||||
{
|
debug_printf ("using value from GetEnvironmentVariable for '%W'", name0);
|
||||||
debug_printf ("using value from GetEnvironmentVariable for '%s'",
|
|
||||||
name0);
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cfree (p);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_printf ("warning: %s not present in environment", name);
|
debug_printf ("warning: %s not present in environment", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -395,7 +395,7 @@ try_to_debug (bool waitloop)
|
||||||
console_printf ("*** starting debugger for pid %u, tid %u\n",
|
console_printf ("*** starting debugger for pid %u, tid %u\n",
|
||||||
cygwin_pid (GetCurrentProcessId ()), GetCurrentThreadId ());
|
cygwin_pid (GetCurrentProcessId ()), GetCurrentThreadId ());
|
||||||
BOOL dbg;
|
BOOL dbg;
|
||||||
sys_mbstowcs (dbg_cmd, debugger_command, sizeof debugger_command);
|
sys_mbstowcs (dbg_cmd, sizeof debugger_command, debugger_command);
|
||||||
dbg = CreateProcessW (NULL,
|
dbg = CreateProcessW (NULL,
|
||||||
dbg_cmd,
|
dbg_cmd,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -121,7 +121,7 @@ set_clipboard (const void *buf, size_t len)
|
||||||
|
|
||||||
OpenClipboard (0);
|
OpenClipboard (0);
|
||||||
|
|
||||||
len = MultiByteToWideChar (get_cp (), 0, (const char *) buf, len, NULL, 0);
|
len = sys_mbstowcs (NULL, 0, (const char *) buf, len);
|
||||||
if (!len)
|
if (!len)
|
||||||
{
|
{
|
||||||
system_printf ("Invalid string");
|
system_printf ("Invalid string");
|
||||||
|
@ -134,7 +134,7 @@ set_clipboard (const void *buf, size_t len)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
clipbuf = GlobalLock (hmem);
|
clipbuf = GlobalLock (hmem);
|
||||||
sys_mbstowcs ((PWCHAR) clipbuf, (const char *) buf, len);
|
sys_mbstowcs ((PWCHAR) clipbuf, len, (const char *) buf);
|
||||||
*((PWCHAR) clipbuf + len) = L'\0';
|
*((PWCHAR) clipbuf + len) = L'\0';
|
||||||
GlobalUnlock (hmem);
|
GlobalUnlock (hmem);
|
||||||
if (!SetClipboardData (CF_UNICODETEXT, hmem))
|
if (!SetClipboardData (CF_UNICODETEXT, hmem))
|
||||||
|
|
|
@ -197,13 +197,12 @@ frok::child (volatile char * volatile here)
|
||||||
cygheap->user.reimpersonate ();
|
cygheap->user.reimpersonate ();
|
||||||
|
|
||||||
#ifdef DEBUGGING
|
#ifdef DEBUGGING
|
||||||
char c;
|
if (GetEnvironmentVariableA ("FORKDEBUG", NULL, 0))
|
||||||
if (GetEnvironmentVariable ("FORKDEBUG", &c, 1))
|
|
||||||
try_to_debug ();
|
try_to_debug ();
|
||||||
char buf[80];
|
char buf[80];
|
||||||
/* This is useful for debugging fork problems. Use gdb to attach to
|
/* This is useful for debugging fork problems. Use gdb to attach to
|
||||||
the pid reported here. */
|
the pid reported here. */
|
||||||
if (GetEnvironmentVariable ("CYGWIN_FORK_SLEEP", buf, sizeof (buf)))
|
if (GetEnvironmentVariableA ("CYGWIN_FORK_SLEEP", buf, sizeof (buf)))
|
||||||
{
|
{
|
||||||
small_printf ("Sleeping %d after fork, pid %u\n", atoi (buf), GetCurrentProcessId ());
|
small_printf ("Sleeping %d after fork, pid %u\n", atoi (buf), GetCurrentProcessId ());
|
||||||
Sleep (atoi (buf));
|
Sleep (atoi (buf));
|
||||||
|
|
|
@ -116,10 +116,10 @@ cygwin_strcasecmp (const char *cs, const char *ct)
|
||||||
|
|
||||||
len = (strlen (cs) + 1) * sizeof (WCHAR);
|
len = (strlen (cs) + 1) * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
||||||
us.Length = sys_mbstowcs (us.Buffer, cs, us.MaximumLength) * sizeof (WCHAR);
|
us.Length = sys_mbstowcs (us.Buffer, us.MaximumLength, cs) * sizeof (WCHAR);
|
||||||
len = (strlen (ct) + 1) * sizeof (WCHAR);
|
len = (strlen (ct) + 1) * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
||||||
ut.Length = sys_mbstowcs (ut.Buffer, ct, ut.MaximumLength) * sizeof (WCHAR);
|
ut.Length = sys_mbstowcs (ut.Buffer, ut.MaximumLength, ct) * sizeof (WCHAR);
|
||||||
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,14 +134,14 @@ cygwin_strncasecmp (const char *cs, const char *ct, size_t n)
|
||||||
++ls;
|
++ls;
|
||||||
len = ls * sizeof (WCHAR);
|
len = ls * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
||||||
us.Length = MultiByteToWideChar (get_cp (), 0, cs, ls, us.Buffer,
|
us.Length = sys_mbstowcs (us.Buffer, us.MaximumLength / sizeof (WCHAR),
|
||||||
us.MaximumLength) * sizeof (WCHAR);
|
cs, ls) * sizeof (WCHAR);
|
||||||
while (ct[lt] && lt < n)
|
while (ct[lt] && lt < n)
|
||||||
++lt;
|
++lt;
|
||||||
len = lt * sizeof (WCHAR);
|
len = lt * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
||||||
ut.Length = MultiByteToWideChar (get_cp (), 0, ct, lt, ut.Buffer,
|
ut.Length = sys_mbstowcs (ut.Buffer, ut.MaximumLength / sizeof (WCHAR),
|
||||||
ut.MaximumLength) * sizeof (WCHAR);
|
ct, lt) * sizeof (WCHAR);
|
||||||
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ cygwin_strlwr (char *string)
|
||||||
size_t len = (strlen (string) + 1) * sizeof (WCHAR);
|
size_t len = (strlen (string) + 1) * sizeof (WCHAR);
|
||||||
|
|
||||||
us.MaximumLength = len; us.Buffer = (PWCHAR) alloca (len);
|
us.MaximumLength = len; us.Buffer = (PWCHAR) alloca (len);
|
||||||
us.Length = sys_mbstowcs (us.Buffer, string, len) * sizeof (WCHAR)
|
us.Length = sys_mbstowcs (us.Buffer, len, string) * sizeof (WCHAR)
|
||||||
- sizeof (WCHAR);
|
- sizeof (WCHAR);
|
||||||
RtlDowncaseUnicodeString (&us, &us, FALSE);
|
RtlDowncaseUnicodeString (&us, &us, FALSE);
|
||||||
sys_wcstombs (string, len / sizeof (WCHAR), us.Buffer);
|
sys_wcstombs (string, len / sizeof (WCHAR), us.Buffer);
|
||||||
|
@ -186,7 +186,7 @@ cygwin_strupr (char *string)
|
||||||
size_t len = (strlen (string) + 1) * sizeof (WCHAR);
|
size_t len = (strlen (string) + 1) * sizeof (WCHAR);
|
||||||
|
|
||||||
us.MaximumLength = len; us.Buffer = (PWCHAR) alloca (len);
|
us.MaximumLength = len; us.Buffer = (PWCHAR) alloca (len);
|
||||||
us.Length = sys_mbstowcs (us.Buffer, string, len) * sizeof (WCHAR)
|
us.Length = sys_mbstowcs (us.Buffer, len, string) * sizeof (WCHAR)
|
||||||
- sizeof (WCHAR);
|
- sizeof (WCHAR);
|
||||||
RtlUpcaseUnicodeString (&us, &us, FALSE);
|
RtlUpcaseUnicodeString (&us, &us, FALSE);
|
||||||
sys_wcstombs (string, len / sizeof (WCHAR), us.Buffer);
|
sys_wcstombs (string, len / sizeof (WCHAR), us.Buffer);
|
||||||
|
|
|
@ -128,7 +128,7 @@ str2buf2uni (UNICODE_STRING &tgt, WCHAR *buf, const char *srcstr)
|
||||||
{
|
{
|
||||||
tgt.Buffer = (PWCHAR) buf;
|
tgt.Buffer = (PWCHAR) buf;
|
||||||
tgt.MaximumLength = (strlen (srcstr) + 1) * sizeof (WCHAR);
|
tgt.MaximumLength = (strlen (srcstr) + 1) * sizeof (WCHAR);
|
||||||
tgt.Length = sys_mbstowcs (buf, srcstr, tgt.MaximumLength / sizeof (WCHAR))
|
tgt.Length = sys_mbstowcs (buf, tgt.MaximumLength / sizeof (WCHAR), srcstr)
|
||||||
* sizeof (WCHAR);
|
* sizeof (WCHAR);
|
||||||
if (tgt.Length)
|
if (tgt.Length)
|
||||||
tgt.Length -= sizeof (WCHAR);
|
tgt.Length -= sizeof (WCHAR);
|
||||||
|
@ -137,8 +137,9 @@ str2buf2uni (UNICODE_STRING &tgt, WCHAR *buf, const char *srcstr)
|
||||||
void
|
void
|
||||||
str2uni_cat (UNICODE_STRING &tgt, const char *srcstr)
|
str2uni_cat (UNICODE_STRING &tgt, const char *srcstr)
|
||||||
{
|
{
|
||||||
int len = sys_mbstowcs (tgt.Buffer + tgt.Length / sizeof (WCHAR), srcstr,
|
int len = sys_mbstowcs (tgt.Buffer + tgt.Length / sizeof (WCHAR),
|
||||||
(tgt.MaximumLength - tgt.Length) / sizeof (WCHAR));
|
(tgt.MaximumLength - tgt.Length) / sizeof (WCHAR),
|
||||||
|
srcstr);
|
||||||
if (len)
|
if (len)
|
||||||
tgt.Length += (len - 1) * sizeof (WCHAR);
|
tgt.Length += (len - 1) * sizeof (WCHAR);
|
||||||
else
|
else
|
||||||
|
@ -186,7 +187,7 @@ get_logon_server (const char *domain, char *server, WCHAR *wserver,
|
||||||
{
|
{
|
||||||
server[0] = server[1] = '\\';
|
server[0] = server[1] = '\\';
|
||||||
if (wserver)
|
if (wserver)
|
||||||
sys_mbstowcs (wserver, server, INTERNET_MAX_HOST_NAME_LENGTH + 1);
|
sys_mbstowcs (wserver, INTERNET_MAX_HOST_NAME_LENGTH + 1, server);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +197,7 @@ get_logon_server (const char *domain, char *server, WCHAR *wserver,
|
||||||
if (dret == ERROR_SUCCESS)
|
if (dret == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
strcpy (server, pci->DomainControllerName);
|
strcpy (server, pci->DomainControllerName);
|
||||||
sys_mbstowcs (wserver, server, INTERNET_MAX_HOST_NAME_LENGTH + 1);
|
sys_mbstowcs (wserver, INTERNET_MAX_HOST_NAME_LENGTH + 1, server);
|
||||||
NetApiBufferFree (pci);
|
NetApiBufferFree (pci);
|
||||||
debug_printf ("DC: rediscovery: %d, server: %s", rediscovery, server);
|
debug_printf ("DC: rediscovery: %d, server: %s", rediscovery, server);
|
||||||
return true;
|
return true;
|
||||||
|
@ -204,7 +205,7 @@ get_logon_server (const char *domain, char *server, WCHAR *wserver,
|
||||||
else if (dret == ERROR_PROC_NOT_FOUND)
|
else if (dret == ERROR_PROC_NOT_FOUND)
|
||||||
{
|
{
|
||||||
/* NT4 w/o DSClient */
|
/* NT4 w/o DSClient */
|
||||||
sys_mbstowcs (wdomain, domain, INTERNET_MAX_HOST_NAME_LENGTH + 1);
|
sys_mbstowcs (wdomain, INTERNET_MAX_HOST_NAME_LENGTH + 1, domain);
|
||||||
if (rediscovery)
|
if (rediscovery)
|
||||||
dret = NetGetAnyDCName (NULL, wdomain, (LPBYTE *) &buf);
|
dret = NetGetAnyDCName (NULL, wdomain, (LPBYTE *) &buf);
|
||||||
else
|
else
|
||||||
|
@ -230,7 +231,7 @@ get_user_groups (WCHAR *wlogonserver, cygsidlist &grp_list, char *user,
|
||||||
{
|
{
|
||||||
char dgroup[INTERNET_MAX_HOST_NAME_LENGTH + GNLEN + 2];
|
char dgroup[INTERNET_MAX_HOST_NAME_LENGTH + GNLEN + 2];
|
||||||
WCHAR wuser[UNLEN + 1];
|
WCHAR wuser[UNLEN + 1];
|
||||||
sys_mbstowcs (wuser, user, UNLEN + 1);
|
sys_mbstowcs (wuser, UNLEN + 1, user);
|
||||||
LPGROUP_USERS_INFO_0 buf;
|
LPGROUP_USERS_INFO_0 buf;
|
||||||
DWORD cnt, tot, len;
|
DWORD cnt, tot, len;
|
||||||
NET_API_STATUS ret;
|
NET_API_STATUS ret;
|
||||||
|
|
|
@ -64,7 +64,7 @@ sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = WideCharToMultiByte (get_cp (), 0, src, slen, NULL, 0,NULL, NULL);
|
ret = WideCharToMultiByte (get_cp (), 0, src, slen, NULL, 0 ,NULL, NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
size_t tlen = (slen == -1 ? ret : ret + 1);
|
size_t tlen = (slen == -1 ? ret : ret + 1);
|
||||||
|
@ -81,28 +81,35 @@ sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen)
|
||||||
}
|
}
|
||||||
|
|
||||||
int __stdcall
|
int __stdcall
|
||||||
sys_mbstowcs (PWCHAR tgt, const char *src, int len)
|
sys_mbstowcs (PWCHAR tgt, int tlen, const char *src, int slen)
|
||||||
{
|
{
|
||||||
int res = MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len);
|
int ret = MultiByteToWideChar (get_cp (), 0, src, slen, tgt, tlen);
|
||||||
return res;
|
if (ret && tgt)
|
||||||
|
{
|
||||||
|
ret = (ret < tlen) ? ret : tlen - 1;
|
||||||
|
tgt[ret] = L'\0';
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Same as sys_wcstombs_alloc, just backwards. */
|
/* Same as sys_wcstombs_alloc, just backwards. */
|
||||||
int __stdcall
|
int __stdcall
|
||||||
sys_mbstowcs_alloc (PWCHAR *tgt_p, int type, const char *src)
|
sys_mbstowcs_alloc (PWCHAR *tgt_p, int type, const char *src, int slen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = MultiByteToWideChar (get_cp (), 0, src, -1, NULL, 0);
|
ret = MultiByteToWideChar (get_cp (), 0, src, slen, NULL, 0);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
|
size_t tlen = (slen == -1 ? ret : ret + 1);
|
||||||
|
|
||||||
if (type == HEAP_NOTHEAP)
|
if (type == HEAP_NOTHEAP)
|
||||||
*tgt_p = (PWCHAR) calloc (ret, sizeof (WCHAR));
|
*tgt_p = (PWCHAR) calloc (tlen, sizeof (WCHAR));
|
||||||
else
|
else
|
||||||
*tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, ret, sizeof (WCHAR));
|
*tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, tlen, sizeof (WCHAR));
|
||||||
if (!*tgt_p)
|
if (!*tgt_p)
|
||||||
return 0;
|
return 0;
|
||||||
ret = sys_mbstowcs (*tgt_p, src, ret);
|
ret = sys_mbstowcs (*tgt_p, tlen, src, slen);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,9 +296,9 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
||||||
if (logsrv ())
|
if (logsrv ())
|
||||||
{
|
{
|
||||||
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
||||||
sys_mbstowcs (wlogsrv, logsrv (),
|
sys_mbstowcs (wlogsrv, sizeof (wlogsrv) / sizeof (*wlogsrv),
|
||||||
sizeof (wlogsrv) / sizeof (*wlogsrv));
|
logsrv ());
|
||||||
sys_mbstowcs (wuser, winname (), sizeof (wuser) / sizeof (*wuser));
|
sys_mbstowcs (wuser, sizeof (wuser) / sizeof (*wuser), winname ());
|
||||||
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui)))
|
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui)))
|
||||||
{
|
{
|
||||||
sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
|
sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
|
||||||
|
|
|
@ -139,9 +139,9 @@ int __stdcall sys_wcstombs (char *, int, const PWCHAR, int = -1)
|
||||||
int __stdcall sys_wcstombs_alloc (char **, int, const PWCHAR, int = -1)
|
int __stdcall sys_wcstombs_alloc (char **, int, const PWCHAR, int = -1)
|
||||||
__attribute__ ((regparm(3)));
|
__attribute__ ((regparm(3)));
|
||||||
|
|
||||||
int __stdcall sys_mbstowcs (PWCHAR, const char *, int)
|
int __stdcall sys_mbstowcs (PWCHAR, int, const char *, int = -1)
|
||||||
__attribute__ ((regparm(3)));
|
__attribute__ ((regparm(3)));
|
||||||
int __stdcall sys_mbstowcs_alloc (PWCHAR *, int, const char *)
|
int __stdcall sys_mbstowcs_alloc (PWCHAR *, int, const char *, int = -1)
|
||||||
__attribute__ ((regparm(3)));
|
__attribute__ ((regparm(3)));
|
||||||
|
|
||||||
/* Used to check if Cygwin DLL is dynamically loaded. */
|
/* Used to check if Cygwin DLL is dynamically loaded. */
|
||||||
|
|
Loading…
Reference in New Issue