]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 25 Dec 2018 00:06:34 +0000 (01:06 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 25 Dec 2018 00:06:34 +0000 (01:06 +0100)
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/cygheap.cc
winsup/cygwin/cygheap.h
winsup/cygwin/environ.cc
winsup/cygwin/mount.cc
winsup/cygwin/uinfo.cc

index 87a5eb9649e9c0cc0f79090bb360a2c93ae68c2c..0e9741c7cee0f7e42b460a57a2d7f2faaf4b662a 100644 (file)
@@ -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;
     }
 }
index d8a2e79a4c6ba266db2c2f3cc1e471d7fcef3503..be088b2248567e0bceabd468a3917b4548f89cea 100644 (file)
@@ -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;
index 67ead1ddec5e96583c0633ef1f160123772328c1..495c340a4163836815c329a36eabce9f4bead2c5 100644 (file)
@@ -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
index 9fd98541dc735dc11e1e4c45dbc4e5b655af3790..1844dd8d02b908cdaf07f214bfec6e4abb8f6ae0 100644 (file)
@@ -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);
 
index c2f4803ceef8f182d885092a6ab4e529bee5fd1e..8dcf731de1165c87a7d38826ca92ab5b54eeb71b 100644 (file)
@@ -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);
     }
This page took 0.041753 seconds and 5 git commands to generate.