kernel32: Add the directory the executable was loaded from to the module search path if the module file name doesn't contain a path.

Robert Shearman rob at codeweavers.com
Tue Apr 24 06:34:35 CDT 2007


---
  dlls/kernel32/module.c |   33 ++++++++++++++++++++++++++-------
  1 files changed, 26 insertions(+), 7 deletions(-)
-------------- next part --------------
diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c
index 9447fd6..daf2714 100644
--- a/dlls/kernel32/module.c
+++ b/dlls/kernel32/module.c
@@ -678,6 +678,24 @@ static const WCHAR *get_dll_system_path(
     return cached_path;
 }
 
+/******************************************************************
+ *		get_module_path_end
+ *
+ * Returns the end of the directory component of the module path.
+ */
+static inline const WCHAR *get_module_path_end(const WCHAR *module)
+{
+    const WCHAR *p;
+    const WCHAR *mod_end = module;
+    if (!module) return mod_end;
+
+    if ((p = strrchrW( mod_end, '\\' ))) mod_end = p;
+    if ((p = strrchrW( mod_end, '/' ))) mod_end = p;
+    if (mod_end == module + 2 && module[1] == ':') mod_end++;
+    if (mod_end == module && module[0] && module[1] == ':') mod_end += 2;
+
+    return mod_end;
+}
 
 /******************************************************************
  *		MODULE_get_dll_load_path
@@ -697,16 +715,17 @@ WCHAR *MODULE_get_dll_load_path( LPCWSTR
 
     /* adjust length for module name */
 
-    if (!module) module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
     if (module)
+        mod_end = get_module_path_end( module );
+    /* if module is NULL or doesn't contain a path, fall back to directory
+     * process was loaded from */
+    if (module == mod_end)
     {
-        mod_end = module;
-        if ((p = strrchrW( mod_end, '\\' ))) mod_end = p;
-        if ((p = strrchrW( mod_end, '/' ))) mod_end = p;
-        if (mod_end == module + 2 && module[1] == ':') mod_end++;
-        if (mod_end == module && module[0] && module[1] == ':') mod_end += 2;
-        len += (mod_end - module) + 1;
+        module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
+        mod_end = get_module_path_end( module );
     }
+    len += (mod_end - module) + 1;
+
     len += strlenW( system_path ) + 2;
 
     /* get the PATH variable */


More information about the wine-patches mailing list