Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user