aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2000-07-22 16:43:54 +0000
committerCorinna Vinschen <corinna@vinschen.de>2000-07-22 16:43:54 +0000
commit9fb628fc5720d1014192a97538ba92d33c9c36ca (patch)
treea8dc304ff3c43b4f0fb4e6036f478e85761f06c1
parent2ff6d12fa29f788a2e27d59ab4ecb5a098ec5ca2 (diff)
downloadnewlib-9fb628fc5720d1014192a97538ba92d33c9c36ca.zip
newlib-9fb628fc5720d1014192a97538ba92d33c9c36ca.tar.gz
newlib-9fb628fc5720d1014192a97538ba92d33c9c36ca.tar.bz2
Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>.
* winsup.h: Add new macros sys_wcstombs and sys_mbstowcs. * syscalls.cc (_link): Replace calls to mbstowcs by call to sys_mbstowcs. * uinfo.cc (internal_getlogin): Replace calls to wcstombs and mbstowcs by calls to sys_wcstombs and sys_mbstowcs. Replace usage of constants by meaningful defines. Use result of GetSystemDirectory for HOMEPATH and HOMEDRIVE as a last resort.
-rw-r--r--winsup/cygwin/ChangeLog11
-rw-r--r--winsup/cygwin/syscalls.cc2
-rw-r--r--winsup/cygwin/uinfo.cc37
-rw-r--r--winsup/cygwin/winsup.h5
4 files changed, 38 insertions, 17 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 7b5ae0b..d4e1ed4 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,14 @@
+Sat Jul 22 18:40:00 2000 Corinna Vinschen <corinna@vinschen.de>
+
+ Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>.
+ * winsup.h: Add new macros sys_wcstombs and sys_mbstowcs.
+ * syscalls.cc (_link): Replace calls to mbstowcs by call to
+ sys_mbstowcs.
+ * uinfo.cc (internal_getlogin): Replace calls to wcstombs and
+ mbstowcs by calls to sys_wcstombs and sys_mbstowcs. Replace
+ usage of constants by meaningful defines. Use result of
+ GetSystemDirectory for HOMEPATH and HOMEDRIVE as a last resort.
+
Fri Jul 21 21:33:00 2000 Corinna Vinschen <corinna@vinschen.de>
* spawn.cc (span_guts): Retrieve security attributes before setting
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 5935bdb..3e67c09 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -547,7 +547,7 @@ _link (const char *a, const char *b)
lpContext = NULL;
cygwin_conv_to_full_win32_path (real_b.get_win32 (), buf);
- cbPathLen = MultiByteToWideChar (CP_ACP, 0, buf, -1, wbuf, MAX_PATH) * sizeof (WCHAR);
+ cbPathLen = sys_mbstowcs (wbuf, buf, MAX_PATH);
StreamId.dwStreamId = BACKUP_LINK;
StreamId.dwStreamAttributes = 0;
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 31378a5..8a19fce 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -30,34 +30,33 @@ internal_getlogin (struct pinfo *pi)
if (os_being_run == winNT)
{
LPWKSTA_USER_INFO_1 wui;
- char buf[256], *env;
+ char buf[MAX_PATH], *env;
+ char *un = NULL;
/* First trying to get logon info from environment */
- buf[0] = '\0';
if ((env = getenv ("USERNAME")) != NULL)
- strcpy (buf, env);
+ un = env;
if ((env = getenv ("LOGONSERVER")) != NULL)
strcpy (pi->logsrv, env + 2); /* filter leading double backslashes */
if ((env = getenv ("USERDOMAIN")) != NULL)
strcpy (pi->domain, env);
/* Trust only if usernames are identical */
- if (strcasematch (pi->username, buf) && pi->domain[0] && pi->logsrv[0])
+ if (un && strcasematch (pi->username, un)
+ && pi->domain[0] && pi->logsrv[0])
debug_printf ("Domain: %s, Logon Server: %s", pi->domain, pi->logsrv);
/* If that failed, try to get that info from NetBIOS */
else if (!NetWkstaUserGetInfo (NULL, 1, (LPBYTE *)&wui))
{
- wcstombs (pi->username, wui->wkui1_username,
- (wcslen (wui->wkui1_username) + 1) * sizeof (WCHAR));
- wcstombs (pi->logsrv, wui->wkui1_logon_server,
- (wcslen (wui->wkui1_logon_server) + 1) * sizeof (WCHAR));
- wcstombs (pi->domain, wui->wkui1_logon_domain,
- (wcslen (wui->wkui1_logon_domain) + 1) * sizeof (WCHAR));
+ sys_wcstombs (pi->username, wui->wkui1_username, MAX_USER_NAME);
+ sys_wcstombs (pi->logsrv, wui->wkui1_logon_server, MAX_HOST_NAME);
+ sys_wcstombs (pi->domain, wui->wkui1_logon_domain,
+ MAX_COMPUTERNAME_LENGTH + 1);
/* Save values in environment */
if (!strcasematch (pi->username, "SYSTEM")
&& pi->domain[0] && pi->logsrv[0])
{
LPUSER_INFO_3 ui = NULL;
- WCHAR wbuf[256];
+ WCHAR wbuf[MAX_HOST_NAME + 2];
strcat (strcpy (buf, "\\\\"), pi->logsrv);
setenv ("USERNAME", pi->username, 1);
@@ -65,19 +64,25 @@ internal_getlogin (struct pinfo *pi)
setenv ("USERDOMAIN", pi->domain, 1);
/* HOMEDRIVE and HOMEPATH are wrong most of the time, too,
after changing user context! */
- mbstowcs (wbuf, buf, 256);
+ sys_mbstowcs (wbuf, buf, MAX_HOST_NAME + 2);
if (!NetUserGetInfo (NULL, wui->wkui1_username, 3, (LPBYTE *)&ui)
|| !NetUserGetInfo (wbuf,wui->wkui1_username,3,(LPBYTE *)&ui))
{
- wcstombs (buf, ui->usri3_home_dir, 256);
+ sys_wcstombs (buf, ui->usri3_home_dir, MAX_PATH);
if (!buf[0])
{
- wcstombs (buf, ui->usri3_home_dir_drive, 256);
+ sys_wcstombs (buf, ui->usri3_home_dir_drive, MAX_PATH);
if (buf[0])
strcat (buf, "\\");
+ else
+ {
+ env = getenv ("SYSTEMDRIVE");
+ if (env && *env)
+ strcat (strcpy (buf, env), "\\");
+ else
+ GetSystemDirectoryA (buf, MAX_PATH);
+ }
}
- if (!buf[0])
- strcat (strcpy (buf, getenv ("SYSTEMDRIVE")), "\\");
setenv ("HOMEPATH", buf + 2, 1);
buf[2] = '\0';
setenv ("HOMEDRIVE", buf, 1);
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index 4141aa7..cb4f5b8 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -60,6 +60,11 @@ extern os_type os_being_run;
/* Used to check if Cygwin DLL is dynamically loaded. */
extern int dynamically_loaded;
+#define sys_wcstombs(tgt,src,len) \
+ WideCharToMultiByte(CP_ACP,0,(src),-1,(tgt),(len),NULL,NULL)
+#define sys_mbstowcs(tgt,src,len) \
+ MultiByteToWideChar(CP_ACP,0,(src),-1,(tgt),(len))
+
#include <cygwin/version.h>
#define TITLESIZE 1024