[newlib-cygwin] Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
Corinna Vinschen
corinna@sourceware.org
Wed Dec 26 09:42:00 GMT 2018
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=866901441b57b4505d8a78aad0caf53bc246ec6e
commit 866901441b57b4505d8a78aad0caf53bc246ec6e
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Tue Dec 25 01:06:34 2018 +0100
Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/cygheap.cc | 28 +++++++++++++++-------------
winsup/cygwin/cygheap.h | 7 ++++---
winsup/cygwin/environ.cc | 5 +++--
winsup/cygwin/mount.cc | 2 +-
winsup/cygwin/uinfo.cc | 13 +++++++------
5 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 87a5eb9..0e9741c 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -139,11 +139,11 @@ init_cygheap::init_installation_root ()
{
ptrdiff_t len = 0;
- if (!GetModuleFileNameW (cygwin_hmodule, installation_root, PATH_MAX))
+ if (!GetModuleFileNameW (cygwin_hmodule, installation_root_buf, PATH_MAX))
api_fatal ("Can't initialize Cygwin installation root dir.\n"
"GetModuleFileNameW(%p, %p, %u), %E",
- cygwin_hmodule, installation_root, PATH_MAX);
- PWCHAR p = installation_root;
+ cygwin_hmodule, installation_root_buf, PATH_MAX);
+ PWCHAR p = installation_root_buf;
if (wcsncasecmp (p, L"\\\\", 2)) /* Normal drive letter path */
{
len = 4;
@@ -170,18 +170,18 @@ init_cygheap::init_installation_root ()
p = wcschr (p + 1, L'\\'); /* Skip share name */
}
}
- installation_root[1] = L'?';
+ installation_root_buf[1] = L'?';
RtlInitEmptyUnicodeString (&installation_key, installation_key_buf,
sizeof installation_key_buf);
- RtlInt64ToHexUnicodeString (hash_path_name (0, installation_root),
+ RtlInt64ToHexUnicodeString (hash_path_name (0, installation_root_buf),
&installation_key, FALSE);
/* Strip off last path component ("\\cygwin1.dll") */
- PWCHAR w = wcsrchr (installation_root, L'\\');
+ PWCHAR w = wcsrchr (installation_root_buf, L'\\');
if (w)
{
*w = L'\0';
- w = wcsrchr (installation_root, L'\\');
+ w = wcsrchr (installation_root_buf, L'\\');
}
if (!w)
api_fatal ("Can't initialize Cygwin installation root dir.\n"
@@ -190,15 +190,14 @@ init_cygheap::init_installation_root ()
/* Copy result into installation_dir before stripping off "bin" dir and
revert to Win32 path. This path is added to the Windows environment
in build_env. See there for a description. */
- installation_dir_len = wcpncpy (installation_dir, installation_root + len,
- PATH_MAX)
- - installation_dir;
+ wcpncpy (installation_dir_buf, installation_root_buf + len, PATH_MAX);
+
if (len == 4) /* Local path */
;
else if (len == 6) /* UNC path */
- installation_dir[0] = L'\\';
+ installation_dir_buf[0] = L'\\';
else /* Long, prefixed path */
- installation_dir[1] = L'\\';
+ installation_dir_buf[1] = L'\\';
/* If w < p, the Cygwin DLL resides in the root dir of a drive or network
path. In that case, if we strip off yet another backslash, the path
@@ -208,12 +207,15 @@ init_cygheap::init_installation_root ()
if (w > p)
*w = L'\0';
+ RtlInitUnicodeString (&installation_root, installation_root_buf);
+ RtlInitUnicodeString (&installation_dir, installation_dir_buf);
+
for (int i = 1; i >= 0; --i)
{
reg_key r (i, KEY_WRITE, _WIDE (CYGWIN_INFO_INSTALLATIONS_NAME),
NULL);
if (NT_SUCCESS (r.set_string (installation_key_buf,
- installation_root)))
+ installation_root_buf)))
break;
}
}
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index d8a2e79..be088b2 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -557,9 +557,10 @@ struct init_cygheap: public mini_cygheap
_cmalloc_entry *chain;
unsigned bucket_val[NBUCKETS];
char *buckets[NBUCKETS];
- WCHAR installation_root[PATH_MAX];
- WCHAR installation_dir[PATH_MAX];
- size_t installation_dir_len;
+ UNICODE_STRING installation_root;
+ WCHAR installation_root_buf[PATH_MAX];
+ UNICODE_STRING installation_dir;
+ WCHAR installation_dir_buf[PATH_MAX];
UNICODE_STRING installation_key;
WCHAR installation_key_buf[18];
cygheap_root root;
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 67ead1d..495c340 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -1282,10 +1282,11 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
during execve. */
if (!saw_PATH)
{
- new_tl += cygheap->installation_dir_len + 5;
+ new_tl += cygheap->installation_dir.Length / sizeof (WCHAR) + 5;
if (new_tl > tl)
tl = raise_envblock (new_tl, envblock, s);
- s = wcpcpy (wcpcpy (s, L"PATH="), cygheap->installation_dir) + 1;
+ s = wcpcpy (wcpcpy (s, L"PATH="),
+ cygheap->installation_dir.Buffer) + 1;
}
*s = L'\0'; /* Two null bytes at the end */
assert ((s - envblock) <= tl); /* Detect if we somehow ran over end
diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index 9fd9854..1844dd8 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -492,7 +492,7 @@ mount_info::init (bool user_init)
PWCHAR pathend;
WCHAR path[PATH_MAX];
- pathend = wcpcpy (path, cygheap->installation_root);
+ pathend = wcpcpy (path, cygheap->installation_root.Buffer);
if (!user_init)
create_root_entry (path);
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index c2f4803..8dcf731 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -1305,11 +1305,11 @@ cygheap_pwdgrp::_nss_init ()
char *buf = tp.c_get ();
PCWSTR rel_path = L"\\etc\\nsswitch.conf";
- path.Length = (wcslen (cygheap->installation_root) + wcslen (rel_path))
- * sizeof (WCHAR);
+ path.Length = cygheap->installation_root.Length
+ + wcslen (rel_path) * sizeof (WCHAR);
path.MaximumLength = path.Length + sizeof (WCHAR);
path.Buffer = (PWCHAR) alloca (path.MaximumLength);
- wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root), rel_path);
+ wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root.Buffer), rel_path);
InitializeObjectAttributes (&attr, &path, OBJ_CASE_INSENSITIVE,
NULL, NULL);
if (rl.init (&attr, buf, NT_MAX_PATH))
@@ -1665,11 +1665,12 @@ pwdgrp::check_file ()
if (!path.Buffer)
{
PCWSTR rel_path = is_group () ? L"\\etc\\group" : L"\\etc\\passwd";
- path.Length = (wcslen (cygheap->installation_root) + wcslen (rel_path))
- * sizeof (WCHAR);
+ path.Length = cygheap->installation_root.Length
+ + wcslen (rel_path) * sizeof (WCHAR);
path.MaximumLength = path.Length + sizeof (WCHAR);
path.Buffer = (PWCHAR) cmalloc_abort (HEAP_BUF, path.MaximumLength);
- wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root), rel_path);
+ wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root.Buffer),
+ rel_path);
InitializeObjectAttributes (&attr, &path, OBJ_CASE_INSENSITIVE,
NULL, NULL);
}
More information about the Cygwin-cvs
mailing list