[PATCH 24/26] [DbgHelp]: unicode: added helper to map a unicode file

Eric Pouech eric.pouech at wanadoo.fr
Wed Feb 21 14:56:32 CST 2007




A+
---

 dlls/dbghelp/elf_module.c |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 6edc0fa..ed2f5a3 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -192,7 +192,7 @@ static inline unsigned elf_get_map_size(
  *
  * Maps an ELF file into memory (and checks it's a real ELF file)
  */
-static BOOL elf_map_file(const char* filename, struct elf_file_map* fmap)
+static BOOL elf_map_fileA(const char* filename, struct elf_file_map* fmap)
 {
     static const BYTE   elf_signature[4] = { ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3 };
     struct stat	        statbuf;
@@ -248,6 +248,20 @@ static BOOL elf_map_file(const char* fil
     return TRUE;
 }
 
+static BOOL elf_map_file(const WCHAR* filenameW, struct elf_file_map* fmap)
+{
+    char*       filename;
+    unsigned    len;
+    BOOL        ret;
+
+    len = WideCharToMultiByte(CP_UNIXCP, 0, filenameW, -1, NULL, 0, NULL, NULL);
+    if (!(filename = HeapAlloc(GetProcessHeap(), 0, len))) return FALSE;
+    WideCharToMultiByte(CP_UNIXCP, 0, filenameW, -1, filename, len, NULL, NULL);
+    ret = elf_map_fileA(filename, fmap);
+    HeapFree(GetProcessHeap(), 0, filename);
+    return ret;
+}
+
 /******************************************************************
  *		elf_unmap_file
  *
@@ -824,21 +838,21 @@ static char* elf_locate_debug_link(const
 
     /* testing execdir/filename */
     strcpy(slash, filename);
-    if (elf_map_file(p, fmap_link)) goto found;
+    if (elf_map_fileA(p, fmap_link)) goto found;
 
     /* testing execdir/.debug/filename */
     sprintf(slash, ".debug/%s", filename);
-    if (elf_map_file(p, fmap_link)) goto found;
+    if (elf_map_fileA(p, fmap_link)) goto found;
 
     /* testing globaldebugdir/execdir/filename */
     memmove(p + globalDebugDirLen, p, slash - p);
     memcpy(p, globalDebugDir, globalDebugDirLen);
     slash += globalDebugDirLen;
     strcpy(slash, filename);
-    if (elf_map_file(p, fmap_link)) goto found;
+    if (elf_map_fileA(p, fmap_link)) goto found;
 
     strcpy(p, filename);
-    if (elf_map_file(p, fmap_link)) goto found;
+    if (elf_map_fileA(p, fmap_link)) goto found;
 
     HeapFree(GetProcessHeap(), 0, p);
 
@@ -1108,12 +1122,8 @@ BOOL elf_load_debug_info(struct module* 
 
     if (!fmap)
     {
-        char    LoadedImageName[MAX_PATH];
-
         fmap = &my_fmap;
-        WideCharToMultiByte(CP_UNIXCP, 0, module->module.LoadedImageName, -1,
-                            LoadedImageName, MAX_PATH, NULL, NULL);
-        ret = elf_map_file(LoadedImageName, fmap);
+        ret = elf_map_file(module->module.LoadedImageName, fmap);
     }
     if (ret)
         ret = elf_load_debug_info_from_map(module, fmap, &pool, &ht_symtab);
@@ -1132,10 +1142,8 @@ BOOL elf_fetch_file_info(const WCHAR* na
                          DWORD* size, DWORD* checksum)
 {
     struct elf_file_map fmap;
-    char                tmp[MAX_PATH];
 
-    WideCharToMultiByte(CP_UNIXCP, 0, name, -1, tmp, sizeof(tmp), 0, 0);
-    if (!elf_map_file(tmp, &fmap)) return FALSE;
+    if (!elf_map_file(name, &fmap)) return FALSE;
     if (base) *base = fmap.elf_start;
     *size = fmap.elf_size;
     *checksum = calc_crc32(&fmap);
@@ -1160,12 +1168,10 @@ static BOOL elf_load_file(struct process
     BOOL                ret = FALSE;
     struct elf_file_map fmap;
     int	       	        i;
-    char                tmp[MAX_PATH];
 
     TRACE("Processing elf file '%s' at %08lx\n", debugstr_w(filename), load_offset);
 
-    WideCharToMultiByte(CP_UNIXCP, 0, filename, -1, tmp, sizeof(tmp), NULL, NULL);    
-    if (!elf_map_file(tmp, &fmap)) goto leave;
+    if (!elf_map_file(filename, &fmap)) goto leave;
 
     /* Next, we need to find a few of the internal ELF headers within
      * this thing.  We need the main executable header, and the section



More information about the wine-patches mailing list