2 * File path.c - managing path in debugging environments
4 * Copyright (C) 2004,2008, Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "dbghelp_private.h"
26 #include "image_private.h"
29 #include "wine/debug.h"
30 #include "wine/heap.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
35 static const WCHAR pe_dir
[] = L
"\\i386-windows";
36 static const WCHAR so_dir
[] = L
"\\i386-unix";
37 #elif defined __x86_64__
38 static const WCHAR pe_dir
[] = L
"\\x86_64-windows";
39 static const WCHAR so_dir
[] = L
"\\x86_64-unix";
41 static const WCHAR pe_dir
[] = L
"\\arm-windows";
42 static const WCHAR so_dir
[] = L
"\\arm-unix";
43 #elif defined __aarch64__
44 static const WCHAR pe_dir
[] = L
"\\aarch64-windows";
45 static const WCHAR so_dir
[] = L
"\\aarch64-unix";
47 static const WCHAR pe_dir
[] = L
"";
48 static const WCHAR so_dir
[] = L
"";
51 static inline BOOL
is_sepA(char ch
) {return ch
== '/' || ch
== '\\';}
52 static inline BOOL
is_sep(WCHAR ch
) {return ch
== '/' || ch
== '\\';}
54 const char* file_nameA(const char* str
)
58 for (p
= str
+ strlen(str
) - 1; p
>= str
&& !is_sepA(*p
); p
--);
62 const WCHAR
* file_name(const WCHAR
* str
)
66 for (p
= str
+ lstrlenW(str
) - 1; p
>= str
&& !is_sep(*p
); p
--);
70 static inline void file_pathW(const WCHAR
*src
, WCHAR
*dst
)
74 for (len
= lstrlenW(src
) - 1; (len
> 0) && (!is_sep(src
[len
])); len
--);
75 memcpy( dst
, src
, len
* sizeof(WCHAR
) );
79 /******************************************************************
80 * FindDebugInfoFile (DBGHELP.@)
83 HANDLE WINAPI
FindDebugInfoFile(PCSTR FileName
, PCSTR SymbolPath
, PSTR DebugFilePath
)
87 h
= CreateFileA(FileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
88 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
89 if (h
== INVALID_HANDLE_VALUE
)
91 if (!SearchPathA(SymbolPath
, file_nameA(FileName
), NULL
, MAX_PATH
, DebugFilePath
, NULL
))
93 h
= CreateFileA(DebugFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
94 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
96 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
99 /******************************************************************
100 * FindDebugInfoFileEx (DBGHELP.@)
103 HANDLE WINAPI
FindDebugInfoFileEx(PCSTR FileName
, PCSTR SymbolPath
,
105 PFIND_DEBUG_FILE_CALLBACK Callback
,
108 FIXME("(%s %s %s %p %p): stub\n", debugstr_a(FileName
), debugstr_a(SymbolPath
),
109 debugstr_a(DebugFilePath
), Callback
, CallerData
);
113 /******************************************************************
114 * FindExecutableImageExW (DBGHELP.@)
117 HANDLE WINAPI
FindExecutableImageExW(PCWSTR FileName
, PCWSTR SymbolPath
, PWSTR ImageFilePath
,
118 PFIND_EXE_FILE_CALLBACKW Callback
, PVOID user
)
122 if (Callback
) FIXME("Unsupported callback yet\n");
123 if (!SearchPathW(SymbolPath
, FileName
, NULL
, MAX_PATH
, ImageFilePath
, NULL
))
125 h
= CreateFileW(ImageFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
126 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
127 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
130 /******************************************************************
131 * FindExecutableImageEx (DBGHELP.@)
134 HANDLE WINAPI
FindExecutableImageEx(PCSTR FileName
, PCSTR SymbolPath
, PSTR ImageFilePath
,
135 PFIND_EXE_FILE_CALLBACK Callback
, PVOID user
)
139 if (Callback
) FIXME("Unsupported callback yet\n");
140 if (!SearchPathA(SymbolPath
, FileName
, NULL
, MAX_PATH
, ImageFilePath
, NULL
))
142 h
= CreateFileA(ImageFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
143 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
144 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
147 /******************************************************************
148 * FindExecutableImage (DBGHELP.@)
151 HANDLE WINAPI
FindExecutableImage(PCSTR FileName
, PCSTR SymbolPath
, PSTR ImageFilePath
)
153 return FindExecutableImageEx(FileName
, SymbolPath
, ImageFilePath
, NULL
, NULL
);
156 /***********************************************************************
157 * MakeSureDirectoryPathExists (DBGHELP.@)
159 BOOL WINAPI
MakeSureDirectoryPathExists(PCSTR DirPath
)
162 const char *p
= DirPath
;
165 if (p
[0] && p
[1] == ':') p
+= 2;
166 while (*p
== '\\') p
++; /* skip drive root */
167 while ((p
= strchr(p
, '\\')) != NULL
)
170 memcpy(path
, DirPath
, n
);
172 if( !CreateDirectoryA(path
, NULL
) &&
173 (GetLastError() != ERROR_ALREADY_EXISTS
))
177 if (GetLastError() == ERROR_ALREADY_EXISTS
)
178 SetLastError(ERROR_SUCCESS
);
183 /******************************************************************
184 * SymMatchFileNameW (DBGHELP.@)
187 BOOL WINAPI
SymMatchFileNameW(PCWSTR file
, PCWSTR match
,
188 PWSTR
* filestop
, PWSTR
* matchstop
)
193 TRACE("(%s %s %p %p)\n",
194 debugstr_w(file
), debugstr_w(match
), filestop
, matchstop
);
196 fptr
= file
+ lstrlenW(file
) - 1;
197 mptr
= match
+ lstrlenW(match
) - 1;
199 while (fptr
>= file
&& mptr
>= match
)
201 if (towupper(*fptr
) != towupper(*mptr
) && !(is_sep(*fptr
) && is_sep(*mptr
)))
205 if (filestop
) *filestop
= (PWSTR
)fptr
;
206 if (matchstop
) *matchstop
= (PWSTR
)mptr
;
208 return mptr
== match
- 1;
211 /******************************************************************
212 * SymMatchFileName (DBGHELP.@)
215 BOOL WINAPI
SymMatchFileName(PCSTR file
, PCSTR match
,
216 PSTR
* filestop
, PSTR
* matchstop
)
221 TRACE("(%s %s %p %p)\n", debugstr_a(file
), debugstr_a(match
), filestop
, matchstop
);
223 fptr
= file
+ strlen(file
) - 1;
224 mptr
= match
+ strlen(match
) - 1;
226 while (fptr
>= file
&& mptr
>= match
)
228 if (toupper(*fptr
) != toupper(*mptr
) && !(is_sepA(*fptr
) && is_sepA(*mptr
)))
232 if (filestop
) *filestop
= (PSTR
)fptr
;
233 if (matchstop
) *matchstop
= (PSTR
)mptr
;
235 return mptr
== match
- 1;
238 static BOOL
do_searchW(PCWSTR file
, PWSTR buffer
, BOOL recurse
,
239 PENUMDIRTREE_CALLBACKW cb
, PVOID user
)
245 static const WCHAR S_AllW
[] = {'*','.','*','\0'};
246 static const WCHAR S_DotW
[] = {'.','\0'};
247 static const WCHAR S_DotDotW
[] = {'.','.','\0'};
249 pos
= lstrlenW(buffer
);
250 if (pos
== 0) return FALSE
;
251 if (buffer
[pos
- 1] != '\\') buffer
[pos
++] = '\\';
252 lstrcpyW(buffer
+ pos
, S_AllW
);
253 if ((h
= FindFirstFileW(buffer
, &fd
)) == INVALID_HANDLE_VALUE
)
255 /* doc doesn't specify how the tree is enumerated...
256 * doing a depth first based on, but may be wrong
260 if (!wcscmp(fd
.cFileName
, S_DotW
) || !wcscmp(fd
.cFileName
, S_DotDotW
)) continue;
262 lstrcpyW(buffer
+ pos
, fd
.cFileName
);
263 if (recurse
&& (fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
264 found
= do_searchW(file
, buffer
, TRUE
, cb
, user
);
265 else if (SymMatchFileNameW(buffer
, file
, NULL
, NULL
))
267 if (!cb
|| cb(buffer
, user
)) found
= TRUE
;
269 } while (!found
&& FindNextFileW(h
, &fd
));
270 if (!found
) buffer
[--pos
] = '\0';
276 /***********************************************************************
277 * SearchTreeForFileW (DBGHELP.@)
279 BOOL WINAPI
SearchTreeForFileW(PCWSTR root
, PCWSTR file
, PWSTR buffer
)
281 TRACE("(%s, %s, %p)\n",
282 debugstr_w(root
), debugstr_w(file
), buffer
);
283 lstrcpyW(buffer
, root
);
284 return do_searchW(file
, buffer
, TRUE
, NULL
, NULL
);
287 /***********************************************************************
288 * SearchTreeForFile (DBGHELP.@)
290 BOOL WINAPI
SearchTreeForFile(PCSTR root
, PCSTR file
, PSTR buffer
)
292 WCHAR rootW
[MAX_PATH
];
293 WCHAR fileW
[MAX_PATH
];
294 WCHAR bufferW
[MAX_PATH
];
297 MultiByteToWideChar(CP_ACP
, 0, root
, -1, rootW
, MAX_PATH
);
298 MultiByteToWideChar(CP_ACP
, 0, file
, -1, fileW
, MAX_PATH
);
299 ret
= SearchTreeForFileW(rootW
, fileW
, bufferW
);
301 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, MAX_PATH
, NULL
, NULL
);
305 /******************************************************************
306 * EnumDirTreeW (DBGHELP.@)
310 BOOL WINAPI
EnumDirTreeW(HANDLE hProcess
, PCWSTR root
, PCWSTR file
,
311 PWSTR buffer
, PENUMDIRTREE_CALLBACKW cb
, PVOID user
)
313 TRACE("(%p %s %s %p %p %p)\n",
314 hProcess
, debugstr_w(root
), debugstr_w(file
), buffer
, cb
, user
);
316 lstrcpyW(buffer
, root
);
317 return do_searchW(file
, buffer
, TRUE
, cb
, user
);
320 /******************************************************************
321 * EnumDirTree (DBGHELP.@)
325 struct enum_dir_treeWA
327 PENUMDIRTREE_CALLBACK cb
;
332 static BOOL CALLBACK
enum_dir_treeWA(PCWSTR name
, PVOID user
)
334 struct enum_dir_treeWA
* edt
= user
;
336 WideCharToMultiByte(CP_ACP
, 0, name
, -1, edt
->name
, MAX_PATH
, NULL
, NULL
);
337 return edt
->cb(edt
->name
, edt
->user
);
340 BOOL WINAPI
EnumDirTree(HANDLE hProcess
, PCSTR root
, PCSTR file
,
341 PSTR buffer
, PENUMDIRTREE_CALLBACK cb
, PVOID user
)
343 WCHAR rootW
[MAX_PATH
];
344 WCHAR fileW
[MAX_PATH
];
345 WCHAR bufferW
[MAX_PATH
];
346 struct enum_dir_treeWA edt
;
351 MultiByteToWideChar(CP_ACP
, 0, root
, -1, rootW
, MAX_PATH
);
352 MultiByteToWideChar(CP_ACP
, 0, file
, -1, fileW
, MAX_PATH
);
353 if ((ret
= EnumDirTreeW(hProcess
, rootW
, fileW
, bufferW
, enum_dir_treeWA
, &edt
)))
354 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, MAX_PATH
, NULL
, NULL
);
360 PFINDFILEINPATHCALLBACKW cb
;
364 /* checks that buffer (as found by matching the name) matches the info
365 * (information is based on file type)
366 * returns TRUE when file is found, FALSE to continue searching
367 * (NB this is the opposite convention of SymFindFileInPathProc)
369 static BOOL CALLBACK
sffip_cb(PCWSTR buffer
, PVOID user
)
371 struct sffip
* s
= user
;
373 if (!s
->cb
) return TRUE
;
374 /* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
375 * convention to stop/continue enumeration. sigh.
377 return !(s
->cb
)(buffer
, s
->user
);
380 /******************************************************************
381 * SymFindFileInPathW (DBGHELP.@)
384 BOOL WINAPI
SymFindFileInPathW(HANDLE hProcess
, PCWSTR searchPath
, PCWSTR full_path
,
385 PVOID id
, DWORD two
, DWORD three
, DWORD flags
,
386 PWSTR buffer
, PFINDFILEINPATHCALLBACKW cb
,
390 struct process
* pcs
= process_find_by_handle(hProcess
);
393 const WCHAR
* filename
;
395 TRACE("(hProcess = %p, searchPath = %s, full_path = %s, id = %p, two = 0x%08x, three = 0x%08x, flags = 0x%08x, buffer = %p, cb = %p, user = %p)\n",
396 hProcess
, debugstr_w(searchPath
), debugstr_w(full_path
),
397 id
, two
, three
, flags
, buffer
, cb
, user
);
399 if (!pcs
) return FALSE
;
400 if (!searchPath
) searchPath
= pcs
->search_path
;
405 filename
= file_name(full_path
);
407 /* first check full path to file */
408 if (sffip_cb(full_path
, &s
))
410 lstrcpyW(buffer
, full_path
);
416 ptr
= wcschr(searchPath
, ';');
419 memcpy(tmp
, searchPath
, (ptr
- searchPath
) * sizeof(WCHAR
));
420 tmp
[ptr
- searchPath
] = 0;
421 searchPath
= ptr
+ 1;
425 lstrcpyW(tmp
, searchPath
);
428 if (do_searchW(filename
, tmp
, FALSE
, sffip_cb
, &s
))
430 lstrcpyW(buffer
, tmp
);
437 /******************************************************************
438 * SymFindFileInPath (DBGHELP.@)
441 BOOL WINAPI
SymFindFileInPath(HANDLE hProcess
, PCSTR searchPath
, PCSTR full_path
,
442 PVOID id
, DWORD two
, DWORD three
, DWORD flags
,
443 PSTR buffer
, PFINDFILEINPATHCALLBACK cb
,
446 WCHAR searchPathW
[MAX_PATH
];
447 WCHAR full_pathW
[MAX_PATH
];
448 WCHAR bufferW
[MAX_PATH
];
449 struct enum_dir_treeWA edt
;
452 /* a PFINDFILEINPATHCALLBACK and a PENUMDIRTREE_CALLBACK have actually the
453 * same signature & semantics, hence we can reuse the EnumDirTree W->A
459 MultiByteToWideChar(CP_ACP
, 0, searchPath
, -1, searchPathW
, MAX_PATH
);
460 MultiByteToWideChar(CP_ACP
, 0, full_path
, -1, full_pathW
, MAX_PATH
);
461 if ((ret
= SymFindFileInPathW(hProcess
, searchPath
? searchPathW
: NULL
, full_pathW
,
462 id
, two
, three
, flags
,
463 bufferW
, enum_dir_treeWA
, &edt
)))
464 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, MAX_PATH
, NULL
, NULL
);
470 enum module_type kind
;
471 /* pe: dw1 DWORD:timestamp
472 * dw2 size of image (from PE header)
473 * pdb: guid PDB guid (if DS PDB file)
474 * or dw1 PDB timestamp (if JG PDB file)
476 * elf: dw1 DWORD:CRC 32 of ELF image (Wine only)
481 WCHAR filename
[MAX_PATH
];
485 /* checks that buffer (as found by matching the name) matches the info
486 * (information is based on file type)
487 * returns TRUE when file is found, FALSE to continue searching
488 * (NB this is the opposite convention of SymFindFileInPathProc)
490 static BOOL CALLBACK
module_find_cb(PCWSTR buffer
, PVOID user
)
492 struct module_find
* mf
= user
;
493 DWORD size
, timestamp
;
494 unsigned matched
= 0;
496 /* the matching weights:
497 * +1 if a file with same name is found and is a decent file of expected type
498 * +1 if first parameter and second parameter match
501 /* FIXME: should check that id/two match the file pointed
511 timestamp
= ~mf
->dw1
;
513 hFile
= CreateFileW(buffer
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
514 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
515 if (hFile
== INVALID_HANDLE_VALUE
) return FALSE
;
516 if ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) != NULL
)
518 if ((mapping
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) != NULL
)
520 IMAGE_NT_HEADERS
* nth
= RtlImageNtHeader(mapping
);
523 UnmapViewOfFile(mapping
);
529 timestamp
= nth
->FileHeader
.TimeDateStamp
;
530 size
= nth
->OptionalHeader
.SizeOfImage
;
531 UnmapViewOfFile(mapping
);
536 if (timestamp
!= mf
->dw1
)
537 WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer
));
539 WARN("Found %s, but wrong size\n", debugstr_w(buffer
));
540 if (timestamp
== mf
->dw1
&& size
== mf
->dw2
) matched
++;
545 struct pdb_lookup pdb_lookup
;
548 WideCharToMultiByte(CP_ACP
, 0, buffer
, -1, fn
, MAX_PATH
, NULL
, NULL
);
549 pdb_lookup
.filename
= fn
;
553 pdb_lookup
.kind
= PDB_DS
;
554 pdb_lookup
.timestamp
= 0;
555 pdb_lookup
.guid
= *mf
->guid
;
559 pdb_lookup
.kind
= PDB_JG
;
560 pdb_lookup
.timestamp
= mf
->dw1
;
561 /* pdb_loopkup.guid = */
563 pdb_lookup
.age
= mf
->dw2
;
565 if (!pdb_fetch_file_info(&pdb_lookup
, &matched
)) return FALSE
;
573 timestamp
= ~mf
->dw1
;
574 hFile
= CreateFileW(buffer
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
575 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
576 if (hFile
== INVALID_HANDLE_VALUE
) return FALSE
;
577 if ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) != NULL
)
579 if ((mapping
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) != NULL
)
581 const IMAGE_SEPARATE_DEBUG_HEADER
* hdr
;
584 if (hdr
->Signature
== IMAGE_SEPARATE_DEBUG_SIGNATURE
)
587 timestamp
= hdr
->TimeDateStamp
;
589 UnmapViewOfFile(mapping
);
594 if (timestamp
== mf
->dw1
) matched
++;
595 else WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer
));
599 FIXME("What the heck??\n");
602 if (matched
> mf
->matched
)
604 lstrcpyW(mf
->filename
, buffer
);
605 mf
->matched
= matched
;
607 /* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
608 * convention to stop/continue enumeration. sigh.
610 return mf
->matched
== 2;
613 BOOL
path_find_symbol_file(const struct process
* pcs
, const struct module
* module
,
614 PCSTR full_path
, enum module_type type
, const GUID
* guid
, DWORD dw1
, DWORD dw2
,
615 WCHAR
*buffer
, BOOL
* is_unmatched
)
617 struct module_find mf
;
618 WCHAR full_pathW
[MAX_PATH
];
620 const WCHAR
* filename
;
621 WCHAR
* searchPath
= pcs
->search_path
;
623 TRACE("(pcs = %p, full_path = %s, guid = %s, dw1 = 0x%08x, dw2 = 0x%08x, buffer = %p)\n",
624 pcs
, debugstr_a(full_path
), debugstr_guid(guid
), dw1
, dw2
, buffer
);
631 MultiByteToWideChar(CP_ACP
, 0, full_path
, -1, full_pathW
, MAX_PATH
);
632 filename
= file_name(full_pathW
);
634 *is_unmatched
= FALSE
;
636 /* first check full path to file */
637 if (module_find_cb(full_pathW
, &mf
))
639 lstrcpyW( buffer
, full_pathW
);
643 /* FIXME: Use Environment-Variables (see MS docs)
644 _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH
645 FIXME: Implement "Standard Path Elements" (Path) ... (see MS docs)
646 do a search for (every?) path-element like this ...
650 (dll may be exe, or sys depending on the file extension) */
652 /* 2. check module-path */
653 file_pathW(module
->module
.LoadedImageName
, buffer
);
654 if (do_searchW(filename
, buffer
, FALSE
, module_find_cb
, &mf
)) return TRUE
;
655 if (module
->real_path
)
657 file_pathW(module
->real_path
, buffer
);
658 if (do_searchW(filename
, buffer
, FALSE
, module_find_cb
, &mf
)) return TRUE
;
663 ptr
= wcschr(searchPath
, ';');
666 memcpy(buffer
, searchPath
, (ptr
- searchPath
) * sizeof(WCHAR
));
667 buffer
[ptr
- searchPath
] = '\0';
668 searchPath
= ptr
+ 1;
672 lstrcpyW(buffer
, searchPath
);
675 /* return first fully matched file */
676 if (do_searchW(filename
, buffer
, FALSE
, module_find_cb
, &mf
)) return TRUE
;
678 /* if no fully matching file is found, return the best matching file if any */
679 if ((dbghelp_options
& SYMOPT_LOAD_ANYTHING
) && mf
.matched
)
681 lstrcpyW( buffer
, mf
.filename
);
682 *is_unmatched
= TRUE
;
688 WCHAR
*get_dos_file_name(const WCHAR
*filename
)
693 if (*filename
== '/')
696 len
= WideCharToMultiByte(CP_UNIXCP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
697 unix_path
= heap_alloc(len
* sizeof(WCHAR
));
698 WideCharToMultiByte(CP_UNIXCP
, 0, filename
, -1, unix_path
, len
, NULL
, NULL
);
699 dos_path
= wine_get_dos_file_name(unix_path
);
700 heap_free(unix_path
);
704 len
= lstrlenW(filename
);
705 dos_path
= heap_alloc((len
+ 1) * sizeof(WCHAR
));
706 memcpy(dos_path
, filename
, (len
+ 1) * sizeof(WCHAR
));
711 BOOL
search_dll_path(const struct process
*process
, const WCHAR
*name
, BOOL (*match
)(void*, HANDLE
, const WCHAR
*), void *param
)
720 name
= file_name(name
);
722 if ((env
= process_getenv(process
, L
"WINEBUILDDIR")))
724 const WCHAR dllsW
[] = { '\\','d','l','l','s','\\' };
725 const WCHAR programsW
[] = { '\\','p','r','o','g','r','a','m','s','\\' };
726 const WCHAR dot_dllW
[] = {'.','d','l','l',0};
727 const WCHAR dot_exeW
[] = {'.','e','x','e',0};
728 const WCHAR dot_soW
[] = {'.','s','o',0};
732 if (!(buf
= heap_alloc((len
+ 8 + 3 * lstrlenW(name
)) * sizeof(WCHAR
)))) return FALSE
;
736 memcpy(end
, dllsW
, sizeof(dllsW
));
737 lstrcpyW(end
+ ARRAY_SIZE(dllsW
), name
);
738 if ((p
= wcsrchr(end
, '.')) && !lstrcmpW(p
, dot_soW
)) *p
= 0;
739 if ((p
= wcsrchr(end
, '.')) && !lstrcmpW(p
, dot_dllW
)) *p
= 0;
740 p
= end
+ lstrlenW(end
);
743 file
= CreateFileW(buf
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
744 if (file
!= INVALID_HANDLE_VALUE
)
746 ret
= match(param
, file
, buf
);
751 memcpy(end
, programsW
, sizeof(programsW
));
752 end
+= ARRAY_SIZE(programsW
);
754 if ((p
= wcsrchr(end
, '.')) && !lstrcmpW(p
, dot_soW
)) *p
= 0;
755 if ((p
= wcsrchr(end
, '.')) && !lstrcmpW(p
, dot_exeW
)) *p
= 0;
756 p
= end
+ lstrlenW(end
);
759 file
= CreateFileW(buf
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
760 if (file
!= INVALID_HANDLE_VALUE
)
762 ret
= match(param
, file
, buf
);
773 swprintf(env_name
, ARRAY_SIZE(env_name
), L
"WINEDLLDIR%u", i
);
774 if (!(env
= process_getenv(process
, env_name
))) return FALSE
;
775 len
= wcslen(env
) + wcslen(pe_dir
) + wcslen(name
) + 2;
776 if (!(buf
= heap_alloc(len
* sizeof(WCHAR
)))) return FALSE
;
777 if ((p
= wcsrchr(name
, '.')) && !lstrcmpW(p
, L
".so"))
778 swprintf(buf
, len
, L
"%s%s\\%s", env
, so_dir
, name
);
780 swprintf(buf
, len
, L
"%s%s\\%s", env
, pe_dir
, name
);
781 file
= CreateFileW(buf
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
782 if (file
!= INVALID_HANDLE_VALUE
)
784 ret
= match(param
, file
, buf
);
788 swprintf(buf
, len
, L
"%s\\%s", env
, name
);
789 file
= CreateFileW(buf
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
790 if (file
!= INVALID_HANDLE_VALUE
)
792 ret
= match(param
, file
, buf
);
802 TRACE("found %s\n", debugstr_w(buf
));
807 BOOL
search_unix_path(const WCHAR
*name
, const WCHAR
*path
, BOOL (*match
)(void*, HANDLE
, const WCHAR
*), void *param
)
809 const WCHAR
*iter
, *next
;
815 if (!path
) return FALSE
;
816 name
= file_name(name
);
818 size
= WideCharToMultiByte(CP_UNIXCP
, 0, name
, -1, NULL
, 0, NULL
, NULL
)
819 + WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, NULL
, 0, NULL
, NULL
);
820 if (!(buf
= heap_alloc(size
))) return FALSE
;
822 for (iter
= path
;; iter
= next
+ 1)
824 if (!(next
= wcschr(iter
, ':'))) next
= iter
+ lstrlenW(iter
);
827 len
= WideCharToMultiByte(CP_UNIXCP
, 0, iter
, next
- iter
, buf
, size
, NULL
, NULL
);
828 if (buf
[len
- 1] != '/') buf
[len
++] = '/';
829 WideCharToMultiByte(CP_UNIXCP
, 0, name
, -1, buf
+ len
, size
- len
, NULL
, NULL
);
830 if ((dos_path
= wine_get_dos_file_name(buf
)))
832 HANDLE file
= CreateFileW(dos_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
833 if (file
!= INVALID_HANDLE_VALUE
)
835 ret
= match(param
, file
, dos_path
);
837 if (ret
) TRACE("found %s\n", debugstr_w(dos_path
));
843 if (*next
!= ':') break;