msacm32/tests: Make acm_driver_func() static.
[wine.git] / dlls / shlwapi / path.c
blob3c07bb8d10aeb7dd61a2f76b9cdafdbc38be23fd
1 /*
2 * Path Functions
4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include <stdlib.h>
29 #include "wine/unicode.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winreg.h"
35 #include "winternl.h"
36 #define NO_SHLWAPI_STREAM
37 #include "shlwapi.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell);
42 /* Get a function pointer from a DLL handle */
43 #define GET_FUNC(func, module, name, fail) \
44 do { \
45 if (!func) { \
46 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
47 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
48 if (!func) return fail; \
49 } \
50 } while (0)
52 /* DLL handles for late bound calls */
53 static HMODULE SHLWAPI_hshell32;
55 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
56 typedef BOOL (WINAPI *fnpIsNetDrive)(int);
57 static fnpIsNetDrive pIsNetDrive;
59 HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR,LPWSTR,DWORD);
61 static inline WCHAR* heap_strdupAtoW(LPCSTR str)
63 WCHAR *ret = NULL;
65 if (str)
67 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
68 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
69 if (ret)
70 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
73 return ret;
76 /*************************************************************************
77 * PathAppendA [SHLWAPI.@]
79 * Append one path to another.
81 * PARAMS
82 * lpszPath [I/O] Initial part of path, and destination for output
83 * lpszAppend [I] Path to append
85 * RETURNS
86 * Success: TRUE. lpszPath contains the newly created path.
87 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
89 * NOTES
90 * lpszAppend must contain at least one backslash ('\') if not NULL.
91 * Because PathCombineA() is used to join the paths, the resulting
92 * path is also canonicalized.
94 BOOL WINAPI PathAppendA (LPSTR lpszPath, LPCSTR lpszAppend)
96 TRACE("(%s,%s)\n",debugstr_a(lpszPath), debugstr_a(lpszAppend));
98 if (lpszPath && lpszAppend)
100 if (!PathIsUNCA(lpszAppend))
101 while (*lpszAppend == '\\')
102 lpszAppend++;
103 if (PathCombineA(lpszPath, lpszPath, lpszAppend))
104 return TRUE;
106 return FALSE;
109 /*************************************************************************
110 * PathAppendW [SHLWAPI.@]
112 * See PathAppendA.
114 BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
116 TRACE("(%s,%s)\n",debugstr_w(lpszPath), debugstr_w(lpszAppend));
118 if (lpszPath && lpszAppend)
120 if (!PathIsUNCW(lpszAppend))
121 while (*lpszAppend == '\\')
122 lpszAppend++;
123 if (PathCombineW(lpszPath, lpszPath, lpszAppend))
124 return TRUE;
126 return FALSE;
129 /*************************************************************************
130 * PathCombineA [SHLWAPI.@]
132 * Combine two paths together.
134 * PARAMS
135 * lpszDest [O] Destination for combined path
136 * lpszDir [I] Directory path
137 * lpszFile [I] File path
139 * RETURNS
140 * Success: The output path
141 * Failure: NULL, if inputs are invalid.
143 * NOTES
144 * lpszDest should be at least MAX_PATH in size, and may point to the same
145 * memory location as lpszDir. The combined path is canonicalised.
147 LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
149 WCHAR szDest[MAX_PATH];
150 WCHAR szDir[MAX_PATH];
151 WCHAR szFile[MAX_PATH];
152 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_a(lpszDir), debugstr_a(lpszFile));
154 /* Invalid parameters */
155 if (!lpszDest)
156 return NULL;
157 if (!lpszDir && !lpszFile)
158 goto fail;
160 if (lpszDir)
161 if (!MultiByteToWideChar(CP_ACP,0,lpszDir,-1,szDir,MAX_PATH))
162 goto fail;
164 if (lpszFile)
165 if (!MultiByteToWideChar(CP_ACP,0,lpszFile,-1,szFile,MAX_PATH))
166 goto fail;
168 if (PathCombineW(szDest, lpszDir ? szDir : NULL, lpszFile ? szFile : NULL))
169 if (WideCharToMultiByte(CP_ACP,0,szDest,-1,lpszDest,MAX_PATH,0,0))
170 return lpszDest;
172 fail:
173 lpszDest[0] = 0;
174 return NULL;
177 /*************************************************************************
178 * PathCombineW [SHLWAPI.@]
180 * See PathCombineA.
182 LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
184 WCHAR szTemp[MAX_PATH];
185 BOOL bUseBoth = FALSE, bStrip = FALSE;
187 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_w(lpszDir), debugstr_w(lpszFile));
189 /* Invalid parameters */
190 if (!lpszDest)
191 return NULL;
192 if (!lpszDir && !lpszFile)
194 lpszDest[0] = 0;
195 return NULL;
198 if ((!lpszFile || !*lpszFile) && lpszDir)
200 /* Use dir only */
201 lstrcpynW(szTemp, lpszDir, MAX_PATH);
203 else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
205 if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
207 /* Use file only */
208 lstrcpynW(szTemp, lpszFile, MAX_PATH);
210 else
212 bUseBoth = TRUE;
213 bStrip = TRUE;
216 else
217 bUseBoth = TRUE;
219 if (bUseBoth)
221 lstrcpynW(szTemp, lpszDir, MAX_PATH);
222 if (bStrip)
224 PathStripToRootW(szTemp);
225 lpszFile++; /* Skip '\' */
227 if (!PathAddBackslashW(szTemp) || strlenW(szTemp) + strlenW(lpszFile) >= MAX_PATH)
229 lpszDest[0] = 0;
230 return NULL;
232 strcatW(szTemp, lpszFile);
235 PathCanonicalizeW(lpszDest, szTemp);
236 return lpszDest;
239 /*************************************************************************
240 * PathAddBackslashA [SHLWAPI.@]
242 * Append a backslash ('\') to a path if one doesn't exist.
244 * PARAMS
245 * lpszPath [I/O] The path to append a backslash to.
247 * RETURNS
248 * Success: The position of the last backslash in the path.
249 * Failure: NULL, if lpszPath is NULL or the path is too large.
251 LPSTR WINAPI PathAddBackslashA(LPSTR lpszPath)
253 size_t iLen;
254 LPSTR prev = lpszPath;
256 TRACE("(%s)\n",debugstr_a(lpszPath));
258 if (!lpszPath || (iLen = strlen(lpszPath)) >= MAX_PATH)
259 return NULL;
261 if (iLen)
263 do {
264 lpszPath = CharNextA(prev);
265 if (*lpszPath)
266 prev = lpszPath;
267 } while (*lpszPath);
268 if (*prev != '\\')
270 *lpszPath++ = '\\';
271 *lpszPath = '\0';
274 return lpszPath;
277 /*************************************************************************
278 * PathAddBackslashW [SHLWAPI.@]
280 * See PathAddBackslashA.
282 LPWSTR WINAPI PathAddBackslashW( LPWSTR lpszPath )
284 size_t iLen;
286 TRACE("(%s)\n",debugstr_w(lpszPath));
288 if (!lpszPath || (iLen = strlenW(lpszPath)) >= MAX_PATH)
289 return NULL;
291 if (iLen)
293 lpszPath += iLen;
294 if (lpszPath[-1] != '\\')
296 *lpszPath++ = '\\';
297 *lpszPath = '\0';
300 return lpszPath;
303 /*************************************************************************
304 * PathBuildRootA [SHLWAPI.@]
306 * Create a root drive string (e.g. "A:\") from a drive number.
308 * PARAMS
309 * lpszPath [O] Destination for the drive string
311 * RETURNS
312 * lpszPath
314 * NOTES
315 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
317 LPSTR WINAPI PathBuildRootA(LPSTR lpszPath, int drive)
319 TRACE("(%p,%d)\n", lpszPath, drive);
321 if (lpszPath && drive >= 0 && drive < 26)
323 lpszPath[0] = 'A' + drive;
324 lpszPath[1] = ':';
325 lpszPath[2] = '\\';
326 lpszPath[3] = '\0';
328 return lpszPath;
331 /*************************************************************************
332 * PathBuildRootW [SHLWAPI.@]
334 * See PathBuildRootA.
336 LPWSTR WINAPI PathBuildRootW(LPWSTR lpszPath, int drive)
338 TRACE("(%p,%d)\n", lpszPath, drive);
340 if (lpszPath && drive >= 0 && drive < 26)
342 lpszPath[0] = 'A' + drive;
343 lpszPath[1] = ':';
344 lpszPath[2] = '\\';
345 lpszPath[3] = '\0';
347 return lpszPath;
350 /*************************************************************************
351 * PathFindFileNameA [SHLWAPI.@]
353 * Locate the start of the file name in a path
355 * PARAMS
356 * lpszPath [I] Path to search
358 * RETURNS
359 * A pointer to the first character of the file name
361 LPSTR WINAPI PathFindFileNameA(LPCSTR lpszPath)
363 LPCSTR lastSlash = lpszPath;
365 TRACE("(%s)\n",debugstr_a(lpszPath));
367 while (lpszPath && *lpszPath)
369 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
370 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
371 lastSlash = lpszPath + 1;
372 lpszPath = CharNextA(lpszPath);
374 return (LPSTR)lastSlash;
377 /*************************************************************************
378 * PathFindFileNameW [SHLWAPI.@]
380 * See PathFindFileNameA.
382 LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
384 LPCWSTR lastSlash = lpszPath;
386 TRACE("(%s)\n",debugstr_w(lpszPath));
388 while (lpszPath && *lpszPath)
390 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
391 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
392 lastSlash = lpszPath + 1;
393 lpszPath++;
395 return (LPWSTR)lastSlash;
398 /*************************************************************************
399 * PathFindExtensionA [SHLWAPI.@]
401 * Locate the start of the file extension in a path
403 * PARAMS
404 * lpszPath [I] The path to search
406 * RETURNS
407 * A pointer to the first character of the extension, the end of
408 * the string if the path has no extension, or NULL If lpszPath is NULL
410 LPSTR WINAPI PathFindExtensionA( LPCSTR lpszPath )
412 LPCSTR lastpoint = NULL;
414 TRACE("(%s)\n", debugstr_a(lpszPath));
416 if (lpszPath)
418 while (*lpszPath)
420 if (*lpszPath == '\\' || *lpszPath==' ')
421 lastpoint = NULL;
422 else if (*lpszPath == '.')
423 lastpoint = lpszPath;
424 lpszPath = CharNextA(lpszPath);
427 return (LPSTR)(lastpoint ? lastpoint : lpszPath);
430 /*************************************************************************
431 * PathFindExtensionW [SHLWAPI.@]
433 * See PathFindExtensionA.
435 LPWSTR WINAPI PathFindExtensionW( LPCWSTR lpszPath )
437 LPCWSTR lastpoint = NULL;
439 TRACE("(%s)\n", debugstr_w(lpszPath));
441 if (lpszPath)
443 while (*lpszPath)
445 if (*lpszPath == '\\' || *lpszPath==' ')
446 lastpoint = NULL;
447 else if (*lpszPath == '.')
448 lastpoint = lpszPath;
449 lpszPath++;
452 return (LPWSTR)(lastpoint ? lastpoint : lpszPath);
455 /*************************************************************************
456 * PathGetArgsA [SHLWAPI.@]
458 * Find the next argument in a string delimited by spaces.
460 * PARAMS
461 * lpszPath [I] The string to search for arguments in
463 * RETURNS
464 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
466 * NOTES
467 * Spaces in quoted strings are ignored as delimiters.
469 LPSTR WINAPI PathGetArgsA(LPCSTR lpszPath)
471 BOOL bSeenQuote = FALSE;
473 TRACE("(%s)\n",debugstr_a(lpszPath));
475 if (lpszPath)
477 while (*lpszPath)
479 if ((*lpszPath==' ') && !bSeenQuote)
480 return (LPSTR)lpszPath + 1;
481 if (*lpszPath == '"')
482 bSeenQuote = !bSeenQuote;
483 lpszPath = CharNextA(lpszPath);
486 return (LPSTR)lpszPath;
489 /*************************************************************************
490 * PathGetArgsW [SHLWAPI.@]
492 * See PathGetArgsA.
494 LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
496 BOOL bSeenQuote = FALSE;
498 TRACE("(%s)\n",debugstr_w(lpszPath));
500 if (lpszPath)
502 while (*lpszPath)
504 if ((*lpszPath==' ') && !bSeenQuote)
505 return (LPWSTR)lpszPath + 1;
506 if (*lpszPath == '"')
507 bSeenQuote = !bSeenQuote;
508 lpszPath++;
511 return (LPWSTR)lpszPath;
514 /*************************************************************************
515 * PathGetDriveNumberA [SHLWAPI.@]
517 * Return the drive number from a path
519 * PARAMS
520 * lpszPath [I] Path to get the drive number from
522 * RETURNS
523 * Success: The drive number corresponding to the drive in the path
524 * Failure: -1, if lpszPath contains no valid drive
526 int WINAPI PathGetDriveNumberA(LPCSTR lpszPath)
528 TRACE ("(%s)\n",debugstr_a(lpszPath));
530 if (lpszPath && !IsDBCSLeadByte(*lpszPath) && lpszPath[1] == ':' &&
531 tolower(*lpszPath) >= 'a' && tolower(*lpszPath) <= 'z')
532 return tolower(*lpszPath) - 'a';
533 return -1;
536 /*************************************************************************
537 * PathGetDriveNumberW [SHLWAPI.@]
539 * See PathGetDriveNumberA.
541 int WINAPI PathGetDriveNumberW(LPCWSTR lpszPath)
543 TRACE ("(%s)\n",debugstr_w(lpszPath));
545 if (lpszPath)
547 WCHAR tl = tolowerW(lpszPath[0]);
548 if (tl >= 'a' && tl <= 'z' && lpszPath[1] == ':')
549 return tl - 'a';
551 return -1;
554 /*************************************************************************
555 * PathRemoveFileSpecA [SHLWAPI.@]
557 * Remove the file specification from a path.
559 * PARAMS
560 * lpszPath [I/O] Path to remove the file spec from
562 * RETURNS
563 * TRUE If the path was valid and modified
564 * FALSE Otherwise
566 BOOL WINAPI PathRemoveFileSpecA(LPSTR lpszPath)
568 LPSTR lpszFileSpec = lpszPath;
569 BOOL bModified = FALSE;
571 TRACE("(%s)\n",debugstr_a(lpszPath));
573 if(lpszPath)
575 /* Skip directory or UNC path */
576 if (*lpszPath == '\\')
577 lpszFileSpec = ++lpszPath;
578 if (*lpszPath == '\\')
579 lpszFileSpec = ++lpszPath;
581 while (*lpszPath)
583 if(*lpszPath == '\\')
584 lpszFileSpec = lpszPath; /* Skip dir */
585 else if(*lpszPath == ':')
587 lpszFileSpec = ++lpszPath; /* Skip drive */
588 if (*lpszPath == '\\')
589 lpszFileSpec++;
591 if (!(lpszPath = CharNextA(lpszPath)))
592 break;
595 if (*lpszFileSpec)
597 *lpszFileSpec = '\0';
598 bModified = TRUE;
601 return bModified;
604 /*************************************************************************
605 * PathRemoveFileSpecW [SHLWAPI.@]
607 * See PathRemoveFileSpecA.
609 BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
611 LPWSTR lpszFileSpec = lpszPath;
612 BOOL bModified = FALSE;
614 TRACE("(%s)\n",debugstr_w(lpszPath));
616 if(lpszPath)
618 /* Skip directory or UNC path */
619 if (*lpszPath == '\\')
620 lpszFileSpec = ++lpszPath;
621 if (*lpszPath == '\\')
622 lpszFileSpec = ++lpszPath;
624 while (*lpszPath)
626 if(*lpszPath == '\\')
627 lpszFileSpec = lpszPath; /* Skip dir */
628 else if(*lpszPath == ':')
630 lpszFileSpec = ++lpszPath; /* Skip drive */
631 if (*lpszPath == '\\')
632 lpszFileSpec++;
634 lpszPath++;
637 if (*lpszFileSpec)
639 *lpszFileSpec = '\0';
640 bModified = TRUE;
643 return bModified;
646 /*************************************************************************
647 * PathStripPathA [SHLWAPI.@]
649 * Remove the initial path from the beginning of a filename
651 * PARAMS
652 * lpszPath [I/O] Path to remove the initial path from
654 * RETURNS
655 * Nothing.
657 void WINAPI PathStripPathA(LPSTR lpszPath)
659 TRACE("(%s)\n", debugstr_a(lpszPath));
661 if (lpszPath)
663 LPSTR lpszFileName = PathFindFileNameA(lpszPath);
664 if(lpszFileName != lpszPath)
665 RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
669 /*************************************************************************
670 * PathStripPathW [SHLWAPI.@]
672 * See PathStripPathA.
674 void WINAPI PathStripPathW(LPWSTR lpszPath)
676 LPWSTR lpszFileName;
678 TRACE("(%s)\n", debugstr_w(lpszPath));
679 lpszFileName = PathFindFileNameW(lpszPath);
680 if(lpszFileName != lpszPath)
681 RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
684 /*************************************************************************
685 * PathStripToRootA [SHLWAPI.@]
687 * Reduce a path to its root.
689 * PARAMS
690 * lpszPath [I/O] the path to reduce
692 * RETURNS
693 * Success: TRUE if the stripped path is a root path
694 * Failure: FALSE if the path cannot be stripped or is NULL
696 BOOL WINAPI PathStripToRootA(LPSTR lpszPath)
698 TRACE("(%s)\n", debugstr_a(lpszPath));
700 if (!lpszPath)
701 return FALSE;
702 while(!PathIsRootA(lpszPath))
703 if (!PathRemoveFileSpecA(lpszPath))
704 return FALSE;
705 return TRUE;
708 /*************************************************************************
709 * PathStripToRootW [SHLWAPI.@]
711 * See PathStripToRootA.
713 BOOL WINAPI PathStripToRootW(LPWSTR lpszPath)
715 TRACE("(%s)\n", debugstr_w(lpszPath));
717 if (!lpszPath)
718 return FALSE;
719 while(!PathIsRootW(lpszPath))
720 if (!PathRemoveFileSpecW(lpszPath))
721 return FALSE;
722 return TRUE;
725 /*************************************************************************
726 * PathRemoveArgsA [SHLWAPI.@]
728 * Strip space separated arguments from a path.
730 * PARAMS
731 * lpszPath [I/O] Path to remove arguments from
733 * RETURNS
734 * Nothing.
736 void WINAPI PathRemoveArgsA(LPSTR lpszPath)
738 TRACE("(%s)\n",debugstr_a(lpszPath));
740 if(lpszPath)
742 LPSTR lpszArgs = PathGetArgsA(lpszPath);
743 if (*lpszArgs)
744 lpszArgs[-1] = '\0';
745 else
747 LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
748 if(*lpszLastChar == ' ')
749 *lpszLastChar = '\0';
754 /*************************************************************************
755 * PathRemoveArgsW [SHLWAPI.@]
757 * See PathRemoveArgsA.
759 void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
761 TRACE("(%s)\n",debugstr_w(lpszPath));
763 if(lpszPath)
765 LPWSTR lpszArgs = PathGetArgsW(lpszPath);
766 if (*lpszArgs || (lpszArgs > lpszPath && lpszArgs[-1] == ' '))
767 lpszArgs[-1] = '\0';
771 /*************************************************************************
772 * PathRemoveExtensionA [SHLWAPI.@]
774 * Remove the file extension from a path
776 * PARAMS
777 * lpszPath [I/O] Path to remove the extension from
779 * NOTES
780 * The NUL terminator must be written only if extension exists
781 * and if the pointed character is not already NUL.
783 * RETURNS
784 * Nothing.
786 void WINAPI PathRemoveExtensionA(LPSTR lpszPath)
788 TRACE("(%s)\n", debugstr_a(lpszPath));
790 if (lpszPath)
792 lpszPath = PathFindExtensionA(lpszPath);
793 if (lpszPath && *lpszPath != '\0')
794 *lpszPath = '\0';
798 /*************************************************************************
799 * PathRemoveExtensionW [SHLWAPI.@]
801 * See PathRemoveExtensionA.
803 void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
805 TRACE("(%s)\n", debugstr_w(lpszPath));
807 if (lpszPath)
809 lpszPath = PathFindExtensionW(lpszPath);
810 if (lpszPath && *lpszPath != '\0')
811 *lpszPath = '\0';
815 /*************************************************************************
816 * PathRemoveBackslashA [SHLWAPI.@]
818 * Remove a trailing backslash from a path.
820 * PARAMS
821 * lpszPath [I/O] Path to remove backslash from
823 * RETURNS
824 * Success: A pointer to the end of the path
825 * Failure: NULL, if lpszPath is NULL
827 LPSTR WINAPI PathRemoveBackslashA( LPSTR lpszPath )
829 LPSTR szTemp = NULL;
831 TRACE("(%s)\n", debugstr_a(lpszPath));
833 if(lpszPath)
835 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
836 if (!PathIsRootA(lpszPath) && *szTemp == '\\')
837 *szTemp = '\0';
839 return szTemp;
842 /*************************************************************************
843 * PathRemoveBackslashW [SHLWAPI.@]
845 * See PathRemoveBackslashA.
847 LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
849 LPWSTR szTemp = NULL;
851 TRACE("(%s)\n", debugstr_w(lpszPath));
853 if(lpszPath)
855 szTemp = lpszPath + strlenW(lpszPath);
856 if (szTemp > lpszPath) szTemp--;
857 if (!PathIsRootW(lpszPath) && *szTemp == '\\')
858 *szTemp = '\0';
860 return szTemp;
863 /*************************************************************************
864 * PathRemoveBlanksA [SHLWAPI.@]
866 * Remove Spaces from the start and end of a path.
868 * PARAMS
869 * lpszPath [I/O] Path to strip blanks from
871 * RETURNS
872 * Nothing.
874 VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
876 TRACE("(%s)\n", debugstr_a(lpszPath));
878 if(lpszPath && *lpszPath)
880 LPSTR start = lpszPath;
882 while (*lpszPath == ' ')
883 lpszPath = CharNextA(lpszPath);
885 while(*lpszPath)
886 *start++ = *lpszPath++;
888 if (start != lpszPath)
889 while (start[-1] == ' ')
890 start--;
891 *start = '\0';
895 /*************************************************************************
896 * PathRemoveBlanksW [SHLWAPI.@]
898 * See PathRemoveBlanksA.
900 VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
902 TRACE("(%s)\n", debugstr_w(lpszPath));
904 if(lpszPath && *lpszPath)
906 LPWSTR start = lpszPath;
908 while (*lpszPath == ' ')
909 lpszPath++;
911 while(*lpszPath)
912 *start++ = *lpszPath++;
914 if (start != lpszPath)
915 while (start[-1] == ' ')
916 start--;
917 *start = '\0';
921 /*************************************************************************
922 * PathQuoteSpacesA [SHLWAPI.@]
924 * Surround a path containing spaces in quotes.
926 * PARAMS
927 * lpszPath [I/O] Path to quote
929 * RETURNS
930 * Nothing.
932 * NOTES
933 * The path is not changed if it is invalid or has no spaces.
935 VOID WINAPI PathQuoteSpacesA(LPSTR lpszPath)
937 TRACE("(%s)\n", debugstr_a(lpszPath));
939 if(lpszPath && StrChrA(lpszPath,' '))
941 size_t iLen = strlen(lpszPath) + 1;
943 if (iLen + 2 < MAX_PATH)
945 memmove(lpszPath + 1, lpszPath, iLen);
946 lpszPath[0] = '"';
947 lpszPath[iLen] = '"';
948 lpszPath[iLen + 1] = '\0';
953 /*************************************************************************
954 * PathQuoteSpacesW [SHLWAPI.@]
956 * See PathQuoteSpacesA.
958 VOID WINAPI PathQuoteSpacesW(LPWSTR lpszPath)
960 TRACE("(%s)\n", debugstr_w(lpszPath));
962 if(lpszPath && StrChrW(lpszPath,' '))
964 int iLen = strlenW(lpszPath) + 1;
966 if (iLen + 2 < MAX_PATH)
968 memmove(lpszPath + 1, lpszPath, iLen * sizeof(WCHAR));
969 lpszPath[0] = '"';
970 lpszPath[iLen] = '"';
971 lpszPath[iLen + 1] = '\0';
976 /*************************************************************************
977 * PathUnquoteSpacesA [SHLWAPI.@]
979 * Remove quotes ("") from around a path, if present.
981 * PARAMS
982 * lpszPath [I/O] Path to strip quotes from
984 * RETURNS
985 * Nothing
987 * NOTES
988 * If the path contains a single quote only, an empty string will result.
989 * Otherwise quotes are only removed if they appear at the start and end
990 * of the path.
992 VOID WINAPI PathUnquoteSpacesA(LPSTR lpszPath)
994 TRACE("(%s)\n", debugstr_a(lpszPath));
996 if (lpszPath && *lpszPath == '"')
998 DWORD dwLen = strlen(lpszPath) - 1;
1000 if (lpszPath[dwLen] == '"')
1002 lpszPath[dwLen] = '\0';
1003 for (; *lpszPath; lpszPath++)
1004 *lpszPath = lpszPath[1];
1009 /*************************************************************************
1010 * PathUnquoteSpacesW [SHLWAPI.@]
1012 * See PathUnquoteSpacesA.
1014 VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
1016 TRACE("(%s)\n", debugstr_w(lpszPath));
1018 if (lpszPath && *lpszPath == '"')
1020 DWORD dwLen = strlenW(lpszPath) - 1;
1022 if (lpszPath[dwLen] == '"')
1024 lpszPath[dwLen] = '\0';
1025 for (; *lpszPath; lpszPath++)
1026 *lpszPath = lpszPath[1];
1031 /*************************************************************************
1032 * PathParseIconLocationA [SHLWAPI.@]
1034 * Parse the location of an icon from a path.
1036 * PARAMS
1037 * lpszPath [I/O] The path to parse the icon location from.
1039 * RETURNS
1040 * Success: The number of the icon
1041 * Failure: 0 if the path does not contain an icon location or is NULL
1043 * NOTES
1044 * The path has surrounding quotes and spaces removed regardless
1045 * of whether the call succeeds or not.
1047 int WINAPI PathParseIconLocationA(LPSTR lpszPath)
1049 int iRet = 0;
1050 LPSTR lpszComma;
1052 TRACE("(%s)\n", debugstr_a(lpszPath));
1054 if (lpszPath)
1056 if ((lpszComma = strchr(lpszPath, ',')))
1058 *lpszComma++ = '\0';
1059 iRet = StrToIntA(lpszComma);
1061 PathUnquoteSpacesA(lpszPath);
1062 PathRemoveBlanksA(lpszPath);
1064 return iRet;
1067 /*************************************************************************
1068 * PathParseIconLocationW [SHLWAPI.@]
1070 * See PathParseIconLocationA.
1072 int WINAPI PathParseIconLocationW(LPWSTR lpszPath)
1074 int iRet = 0;
1075 LPWSTR lpszComma;
1077 TRACE("(%s)\n", debugstr_w(lpszPath));
1079 if (lpszPath)
1081 if ((lpszComma = StrChrW(lpszPath, ',')))
1083 *lpszComma++ = '\0';
1084 iRet = StrToIntW(lpszComma);
1086 PathUnquoteSpacesW(lpszPath);
1087 PathRemoveBlanksW(lpszPath);
1089 return iRet;
1092 /*************************************************************************
1093 * @ [SHLWAPI.4]
1095 * Unicode version of PathFileExistsDefExtA.
1097 BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath,DWORD dwWhich)
1099 static const WCHAR pszExts[][5] = { { '.', 'p', 'i', 'f', 0},
1100 { '.', 'c', 'o', 'm', 0},
1101 { '.', 'e', 'x', 'e', 0},
1102 { '.', 'b', 'a', 't', 0},
1103 { '.', 'l', 'n', 'k', 0},
1104 { '.', 'c', 'm', 'd', 0},
1105 { 0, 0, 0, 0, 0} };
1107 TRACE("(%s,%d)\n", debugstr_w(lpszPath), dwWhich);
1109 if (!lpszPath || PathIsUNCServerW(lpszPath) || PathIsUNCServerShareW(lpszPath))
1110 return FALSE;
1112 if (dwWhich)
1114 LPCWSTR szExt = PathFindExtensionW(lpszPath);
1115 if (!*szExt || dwWhich & 0x40)
1117 size_t iChoose = 0;
1118 int iLen = lstrlenW(lpszPath);
1119 if (iLen > (MAX_PATH - 5))
1120 return FALSE;
1121 while ( (dwWhich & 0x1) && pszExts[iChoose][0] )
1123 lstrcpyW(lpszPath + iLen, pszExts[iChoose]);
1124 if (PathFileExistsW(lpszPath))
1125 return TRUE;
1126 iChoose++;
1127 dwWhich >>= 1;
1129 *(lpszPath + iLen) = (WCHAR)'\0';
1130 return FALSE;
1133 return PathFileExistsW(lpszPath);
1136 /*************************************************************************
1137 * @ [SHLWAPI.3]
1139 * Determine if a file exists locally and is of an executable type.
1141 * PARAMS
1142 * lpszPath [I/O] File to search for
1143 * dwWhich [I] Type of executable to search for
1145 * RETURNS
1146 * TRUE If the file was found. lpszPath contains the file name.
1147 * FALSE Otherwise.
1149 * NOTES
1150 * lpszPath is modified in place and must be at least MAX_PATH in length.
1151 * If the function returns FALSE, the path is modified to its original state.
1152 * If the given path contains an extension or dwWhich is 0, executable
1153 * extensions are not checked.
1155 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1156 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1157 * their own developers exclusive use. Monopoly, anyone?
1159 BOOL WINAPI PathFileExistsDefExtA(LPSTR lpszPath,DWORD dwWhich)
1161 BOOL bRet = FALSE;
1163 TRACE("(%s,%d)\n", debugstr_a(lpszPath), dwWhich);
1165 if (lpszPath)
1167 WCHAR szPath[MAX_PATH];
1168 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
1169 bRet = PathFileExistsDefExtW(szPath, dwWhich);
1170 if (bRet)
1171 WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
1173 return bRet;
1176 /*************************************************************************
1177 * SHLWAPI_PathFindInOtherDirs
1179 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1181 static BOOL SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
1183 static const WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
1184 static const WCHAR szPath[] = { 'P','A','T','H','\0'};
1185 DWORD dwLenPATH;
1186 LPCWSTR lpszCurr;
1187 WCHAR *lpszPATH;
1188 WCHAR buff[MAX_PATH];
1190 TRACE("(%s,%08x)\n", debugstr_w(lpszFile), dwWhich);
1192 /* Try system directories */
1193 GetSystemDirectoryW(buff, MAX_PATH);
1194 if (!PathAppendW(buff, lpszFile))
1195 return FALSE;
1196 if (PathFileExistsDefExtW(buff, dwWhich))
1198 strcpyW(lpszFile, buff);
1199 return TRUE;
1201 GetWindowsDirectoryW(buff, MAX_PATH);
1202 if (!PathAppendW(buff, szSystem ) || !PathAppendW(buff, lpszFile))
1203 return FALSE;
1204 if (PathFileExistsDefExtW(buff, dwWhich))
1206 strcpyW(lpszFile, buff);
1207 return TRUE;
1209 GetWindowsDirectoryW(buff, MAX_PATH);
1210 if (!PathAppendW(buff, lpszFile))
1211 return FALSE;
1212 if (PathFileExistsDefExtW(buff, dwWhich))
1214 strcpyW(lpszFile, buff);
1215 return TRUE;
1217 /* Try dirs listed in %PATH% */
1218 dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
1220 if (!dwLenPATH || !(lpszPATH = HeapAlloc(GetProcessHeap(), 0, (dwLenPATH + 1) * sizeof (WCHAR))))
1221 return FALSE;
1223 GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
1224 lpszCurr = lpszPATH;
1225 while (lpszCurr)
1227 LPCWSTR lpszEnd = lpszCurr;
1228 LPWSTR pBuff = buff;
1230 while (*lpszEnd == ' ')
1231 lpszEnd++;
1232 while (*lpszEnd && *lpszEnd != ';')
1233 *pBuff++ = *lpszEnd++;
1234 *pBuff = '\0';
1236 if (*lpszEnd)
1237 lpszCurr = lpszEnd + 1;
1238 else
1239 lpszCurr = NULL; /* Last Path, terminate after this */
1241 if (!PathAppendW(buff, lpszFile))
1243 HeapFree(GetProcessHeap(), 0, lpszPATH);
1244 return FALSE;
1246 if (PathFileExistsDefExtW(buff, dwWhich))
1248 strcpyW(lpszFile, buff);
1249 HeapFree(GetProcessHeap(), 0, lpszPATH);
1250 return TRUE;
1253 HeapFree(GetProcessHeap(), 0, lpszPATH);
1254 return FALSE;
1257 /*************************************************************************
1258 * @ [SHLWAPI.5]
1260 * Search a range of paths for a specific type of executable.
1262 * PARAMS
1263 * lpszFile [I/O] File to search for
1264 * lppszOtherDirs [I] Other directories to look in
1265 * dwWhich [I] Type of executable to search for
1267 * RETURNS
1268 * Success: TRUE. The path to the executable is stored in lpszFile.
1269 * Failure: FALSE. The path to the executable is unchanged.
1271 BOOL WINAPI PathFindOnPathExA(LPSTR lpszFile,LPCSTR *lppszOtherDirs,DWORD dwWhich)
1273 WCHAR szFile[MAX_PATH];
1274 WCHAR buff[MAX_PATH];
1276 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
1278 if (!lpszFile || !PathIsFileSpecA(lpszFile))
1279 return FALSE;
1281 MultiByteToWideChar(CP_ACP,0,lpszFile,-1,szFile,MAX_PATH);
1283 /* Search provided directories first */
1284 if (lppszOtherDirs && *lppszOtherDirs)
1286 WCHAR szOther[MAX_PATH];
1287 LPCSTR *lpszOtherPath = lppszOtherDirs;
1289 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1291 MultiByteToWideChar(CP_ACP,0,*lpszOtherPath,-1,szOther,MAX_PATH);
1292 PathCombineW(buff, szOther, szFile);
1293 if (PathFileExistsDefExtW(buff, dwWhich))
1295 WideCharToMultiByte(CP_ACP,0,buff,-1,lpszFile,MAX_PATH,0,0);
1296 return TRUE;
1298 lpszOtherPath++;
1301 /* Not found, try system and path dirs */
1302 if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
1304 WideCharToMultiByte(CP_ACP,0,szFile,-1,lpszFile,MAX_PATH,0,0);
1305 return TRUE;
1307 return FALSE;
1310 /*************************************************************************
1311 * @ [SHLWAPI.6]
1313 * Unicode version of PathFindOnPathExA.
1315 BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile,LPCWSTR *lppszOtherDirs,DWORD dwWhich)
1317 WCHAR buff[MAX_PATH];
1319 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
1321 if (!lpszFile || !PathIsFileSpecW(lpszFile))
1322 return FALSE;
1324 /* Search provided directories first */
1325 if (lppszOtherDirs && *lppszOtherDirs)
1327 LPCWSTR *lpszOtherPath = lppszOtherDirs;
1328 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1330 PathCombineW(buff, *lpszOtherPath, lpszFile);
1331 if (PathFileExistsDefExtW(buff, dwWhich))
1333 strcpyW(lpszFile, buff);
1334 return TRUE;
1336 lpszOtherPath++;
1339 /* Not found, try system and path dirs */
1340 return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
1343 /*************************************************************************
1344 * PathFindOnPathA [SHLWAPI.@]
1346 * Search a range of paths for an executable.
1348 * PARAMS
1349 * lpszFile [I/O] File to search for
1350 * lppszOtherDirs [I] Other directories to look in
1352 * RETURNS
1353 * Success: TRUE. The path to the executable is stored in lpszFile.
1354 * Failure: FALSE. The path to the executable is unchanged.
1356 BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
1358 TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
1359 return PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
1362 /*************************************************************************
1363 * PathFindOnPathW [SHLWAPI.@]
1365 * See PathFindOnPathA.
1367 BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
1369 TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
1370 return PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
1373 /*************************************************************************
1374 * PathCompactPathExA [SHLWAPI.@]
1376 * Compact a path into a given number of characters.
1378 * PARAMS
1379 * lpszDest [O] Destination for compacted path
1380 * lpszPath [I] Source path
1381 * cchMax [I] Maximum size of compacted path
1382 * dwFlags [I] Reserved
1384 * RETURNS
1385 * Success: TRUE. The compacted path is written to lpszDest.
1386 * Failure: FALSE. lpszPath is undefined.
1388 * NOTES
1389 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1391 * The Win32 version of this function contains a bug: When cchMax == 7,
1392 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1393 * implementation.
1395 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1396 * because Win32 will insert a "\" in lpszDest, even if one is
1397 * not present in the original path.
1399 BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
1400 UINT cchMax, DWORD dwFlags)
1402 BOOL bRet = FALSE;
1404 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
1406 if (lpszPath && lpszDest)
1408 WCHAR szPath[MAX_PATH];
1409 WCHAR szDest[MAX_PATH];
1411 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
1412 szDest[0] = '\0';
1413 bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
1414 WideCharToMultiByte(CP_ACP,0,szDest,-1,lpszDest,MAX_PATH,0,0);
1416 return bRet;
1419 /*************************************************************************
1420 * PathCompactPathExW [SHLWAPI.@]
1422 * See PathCompactPathExA.
1424 BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
1425 UINT cchMax, DWORD dwFlags)
1427 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
1428 LPCWSTR lpszFile;
1429 DWORD dwLen, dwFileLen = 0;
1431 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
1433 if (!lpszPath)
1434 return FALSE;
1436 if (!lpszDest)
1438 WARN("Invalid lpszDest would crash under Win32!\n");
1439 return FALSE;
1442 *lpszDest = '\0';
1444 if (cchMax < 2)
1445 return TRUE;
1447 dwLen = strlenW(lpszPath) + 1;
1449 if (dwLen < cchMax)
1451 /* Don't need to compact */
1452 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1453 return TRUE;
1456 /* Path must be compacted to fit into lpszDest */
1457 lpszFile = PathFindFileNameW(lpszPath);
1458 dwFileLen = lpszPath + dwLen - lpszFile;
1460 if (dwFileLen == dwLen)
1462 /* No root in psth */
1463 if (cchMax <= 4)
1465 while (--cchMax > 0) /* No room left for anything but ellipses */
1466 *lpszDest++ = '.';
1467 *lpszDest = '\0';
1468 return TRUE;
1470 /* Compact the file name with ellipses at the end */
1471 cchMax -= 4;
1472 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1473 strcpyW(lpszDest + cchMax, szEllipses);
1474 return TRUE;
1476 /* We have a root in the path */
1477 lpszFile--; /* Start compacted filename with the path separator */
1478 dwFileLen++;
1480 if (dwFileLen + 3 > cchMax)
1482 /* Compact the file name */
1483 if (cchMax <= 4)
1485 while (--cchMax > 0) /* No room left for anything but ellipses */
1486 *lpszDest++ = '.';
1487 *lpszDest = '\0';
1488 return TRUE;
1490 strcpyW(lpszDest, szEllipses);
1491 lpszDest += 3;
1492 cchMax -= 4;
1493 *lpszDest++ = *lpszFile++;
1494 if (cchMax <= 4)
1496 while (--cchMax > 0) /* No room left for anything but ellipses */
1497 *lpszDest++ = '.';
1498 *lpszDest = '\0';
1499 return TRUE;
1501 cchMax -= 4;
1502 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1503 strcpyW(lpszDest + cchMax, szEllipses);
1504 return TRUE;
1507 /* Only the root needs to be Compacted */
1508 dwLen = cchMax - dwFileLen - 3;
1509 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1510 strcpyW(lpszDest + dwLen, szEllipses);
1511 strcpyW(lpszDest + dwLen + 3, lpszFile);
1512 return TRUE;
1515 /*************************************************************************
1516 * PathIsRelativeA [SHLWAPI.@]
1518 * Determine if a path is a relative path.
1520 * PARAMS
1521 * lpszPath [I] Path to check
1523 * RETURNS
1524 * TRUE: The path is relative, or is invalid.
1525 * FALSE: The path is not relative.
1527 BOOL WINAPI PathIsRelativeA (LPCSTR lpszPath)
1529 TRACE("(%s)\n",debugstr_a(lpszPath));
1531 if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
1532 return TRUE;
1533 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1534 return FALSE;
1535 return TRUE;
1538 /*************************************************************************
1539 * PathIsRelativeW [SHLWAPI.@]
1541 * See PathIsRelativeA.
1543 BOOL WINAPI PathIsRelativeW (LPCWSTR lpszPath)
1545 TRACE("(%s)\n",debugstr_w(lpszPath));
1547 if (!lpszPath || !*lpszPath)
1548 return TRUE;
1549 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1550 return FALSE;
1551 return TRUE;
1554 /*************************************************************************
1555 * PathIsRootA [SHLWAPI.@]
1557 * Determine if a path is a root path.
1559 * PARAMS
1560 * lpszPath [I] Path to check
1562 * RETURNS
1563 * TRUE If lpszPath is valid and a root path,
1564 * FALSE Otherwise
1566 BOOL WINAPI PathIsRootA(LPCSTR lpszPath)
1568 TRACE("(%s)\n", debugstr_a(lpszPath));
1570 if (lpszPath && *lpszPath)
1572 if (*lpszPath == '\\')
1574 if (!lpszPath[1])
1575 return TRUE; /* \ */
1576 else if (lpszPath[1]=='\\')
1578 BOOL bSeenSlash = FALSE;
1579 lpszPath += 2;
1581 /* Check for UNC root path */
1582 while (*lpszPath)
1584 if (*lpszPath == '\\')
1586 if (bSeenSlash)
1587 return FALSE;
1588 bSeenSlash = TRUE;
1590 lpszPath = CharNextA(lpszPath);
1592 return TRUE;
1595 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1596 return TRUE; /* X:\ */
1598 return FALSE;
1601 /*************************************************************************
1602 * PathIsRootW [SHLWAPI.@]
1604 * See PathIsRootA.
1606 BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
1608 TRACE("(%s)\n", debugstr_w(lpszPath));
1610 if (lpszPath && *lpszPath)
1612 if (*lpszPath == '\\')
1614 if (!lpszPath[1])
1615 return TRUE; /* \ */
1616 else if (lpszPath[1]=='\\')
1618 BOOL bSeenSlash = FALSE;
1619 lpszPath += 2;
1621 /* Check for UNC root path */
1622 while (*lpszPath)
1624 if (*lpszPath == '\\')
1626 if (bSeenSlash)
1627 return FALSE;
1628 bSeenSlash = TRUE;
1630 lpszPath++;
1632 return TRUE;
1635 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1636 return TRUE; /* X:\ */
1638 return FALSE;
1641 /*************************************************************************
1642 * PathIsDirectoryA [SHLWAPI.@]
1644 * Determine if a path is a valid directory
1646 * PARAMS
1647 * lpszPath [I] Path to check.
1649 * RETURNS
1650 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1651 * FALSE if lpszPath is invalid or not a directory.
1653 * NOTES
1654 * Although this function is prototyped as returning a BOOL, it returns
1655 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1657 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1658 *| ...
1660 * will always fail.
1662 BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
1664 DWORD dwAttr;
1666 TRACE("(%s)\n", debugstr_a(lpszPath));
1668 if (!lpszPath || PathIsUNCServerA(lpszPath))
1669 return FALSE;
1671 if (PathIsUNCServerShareA(lpszPath))
1673 FIXME("UNC Server Share not yet supported - FAILING\n");
1674 return FALSE;
1677 if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1678 return FALSE;
1679 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1682 /*************************************************************************
1683 * PathIsDirectoryW [SHLWAPI.@]
1685 * See PathIsDirectoryA.
1687 BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
1689 DWORD dwAttr;
1691 TRACE("(%s)\n", debugstr_w(lpszPath));
1693 if (!lpszPath || PathIsUNCServerW(lpszPath))
1694 return FALSE;
1696 if (PathIsUNCServerShareW(lpszPath))
1698 FIXME("UNC Server Share not yet supported - FAILING\n");
1699 return FALSE;
1702 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1703 return FALSE;
1704 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1707 /*************************************************************************
1708 * PathFileExistsA [SHLWAPI.@]
1710 * Determine if a file exists.
1712 * PARAMS
1713 * lpszPath [I] Path to check
1715 * RETURNS
1716 * TRUE If the file exists and is readable
1717 * FALSE Otherwise
1719 BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
1721 UINT iPrevErrMode;
1722 DWORD dwAttr;
1724 TRACE("(%s)\n",debugstr_a(lpszPath));
1726 if (!lpszPath)
1727 return FALSE;
1729 /* Prevent a dialog box if path is on a disk that has been ejected. */
1730 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1731 dwAttr = GetFileAttributesA(lpszPath);
1732 SetErrorMode(iPrevErrMode);
1733 return dwAttr != INVALID_FILE_ATTRIBUTES;
1736 /*************************************************************************
1737 * PathFileExistsW [SHLWAPI.@]
1739 * See PathFileExistsA.
1741 BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
1743 UINT iPrevErrMode;
1744 DWORD dwAttr;
1746 TRACE("(%s)\n",debugstr_w(lpszPath));
1748 if (!lpszPath)
1749 return FALSE;
1751 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1752 dwAttr = GetFileAttributesW(lpszPath);
1753 SetErrorMode(iPrevErrMode);
1754 return dwAttr != INVALID_FILE_ATTRIBUTES;
1757 /*************************************************************************
1758 * PathFileExistsAndAttributesA [SHLWAPI.445]
1760 * Determine if a file exists.
1762 * PARAMS
1763 * lpszPath [I] Path to check
1764 * dwAttr [O] attributes of file
1766 * RETURNS
1767 * TRUE If the file exists and is readable
1768 * FALSE Otherwise
1770 BOOL WINAPI PathFileExistsAndAttributesA(LPCSTR lpszPath, DWORD *dwAttr)
1772 UINT iPrevErrMode;
1773 DWORD dwVal = 0;
1775 TRACE("(%s %p)\n", debugstr_a(lpszPath), dwAttr);
1777 if (dwAttr)
1778 *dwAttr = INVALID_FILE_ATTRIBUTES;
1780 if (!lpszPath)
1781 return FALSE;
1783 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1784 dwVal = GetFileAttributesA(lpszPath);
1785 SetErrorMode(iPrevErrMode);
1786 if (dwAttr)
1787 *dwAttr = dwVal;
1788 return (dwVal != INVALID_FILE_ATTRIBUTES);
1791 /*************************************************************************
1792 * PathFileExistsAndAttributesW [SHLWAPI.446]
1794 * See PathFileExistsA.
1796 BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
1798 UINT iPrevErrMode;
1799 DWORD dwVal;
1801 TRACE("(%s %p)\n", debugstr_w(lpszPath), dwAttr);
1803 if (!lpszPath)
1804 return FALSE;
1806 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1807 dwVal = GetFileAttributesW(lpszPath);
1808 SetErrorMode(iPrevErrMode);
1809 if (dwAttr)
1810 *dwAttr = dwVal;
1811 return (dwVal != INVALID_FILE_ATTRIBUTES);
1814 /*************************************************************************
1815 * PathMatchSingleMaskA [internal]
1817 static BOOL PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
1819 while (*name && *mask && *mask!=';')
1821 if (*mask == '*')
1825 if (PathMatchSingleMaskA(name,mask+1))
1826 return TRUE; /* try substrings */
1827 } while (*name++);
1828 return FALSE;
1831 if (toupper(*mask) != toupper(*name) && *mask != '?')
1832 return FALSE;
1834 name = CharNextA(name);
1835 mask = CharNextA(mask);
1838 if (!*name)
1840 while (*mask == '*')
1841 mask++;
1842 if (!*mask || *mask == ';')
1843 return TRUE;
1845 return FALSE;
1848 /*************************************************************************
1849 * PathMatchSingleMaskW [internal]
1851 static BOOL PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
1853 while (*name && *mask && *mask != ';')
1855 if (*mask == '*')
1859 if (PathMatchSingleMaskW(name,mask+1))
1860 return TRUE; /* try substrings */
1861 } while (*name++);
1862 return FALSE;
1865 if (toupperW(*mask) != toupperW(*name) && *mask != '?')
1866 return FALSE;
1868 name++;
1869 mask++;
1871 if (!*name)
1873 while (*mask == '*')
1874 mask++;
1875 if (!*mask || *mask == ';')
1876 return TRUE;
1878 return FALSE;
1881 /*************************************************************************
1882 * PathMatchSpecA [SHLWAPI.@]
1884 * Determine if a path matches one or more search masks.
1886 * PARAMS
1887 * lpszPath [I] Path to check
1888 * lpszMask [I] Search mask(s)
1890 * RETURNS
1891 * TRUE If lpszPath is valid and is matched
1892 * FALSE Otherwise
1894 * NOTES
1895 * Multiple search masks may be given if they are separated by ";". The
1896 * pattern "*.*" is treated specially in that it matches all paths (for
1897 * backwards compatibility with DOS).
1899 BOOL WINAPI PathMatchSpecA(LPCSTR lpszPath, LPCSTR lpszMask)
1901 TRACE("(%s,%s)\n", lpszPath, lpszMask);
1903 if (!lstrcmpA(lpszMask, "*.*"))
1904 return TRUE; /* Matches every path */
1906 while (*lpszMask)
1908 while (*lpszMask == ' ')
1909 lpszMask++; /* Eat leading spaces */
1911 if (PathMatchSingleMaskA(lpszPath, lpszMask))
1912 return TRUE; /* Matches the current mask */
1914 while (*lpszMask && *lpszMask != ';')
1915 lpszMask = CharNextA(lpszMask); /* masks separated by ';' */
1917 if (*lpszMask == ';')
1918 lpszMask++;
1920 return FALSE;
1923 /*************************************************************************
1924 * PathMatchSpecW [SHLWAPI.@]
1926 * See PathMatchSpecA.
1928 BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
1930 static const WCHAR szStarDotStar[] = { '*', '.', '*', '\0' };
1932 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszMask));
1934 if (!lstrcmpW(lpszMask, szStarDotStar))
1935 return TRUE; /* Matches every path */
1937 while (*lpszMask)
1939 while (*lpszMask == ' ')
1940 lpszMask++; /* Eat leading spaces */
1942 if (PathMatchSingleMaskW(lpszPath, lpszMask))
1943 return TRUE; /* Matches the current path */
1945 while (*lpszMask && *lpszMask != ';')
1946 lpszMask++; /* masks separated by ';' */
1948 if (*lpszMask == ';')
1949 lpszMask++;
1951 return FALSE;
1954 /*************************************************************************
1955 * PathIsSameRootA [SHLWAPI.@]
1957 * Determine if two paths share the same root.
1959 * PARAMS
1960 * lpszPath1 [I] Source path
1961 * lpszPath2 [I] Path to compare with
1963 * RETURNS
1964 * TRUE If both paths are valid and share the same root.
1965 * FALSE If either path is invalid or the paths do not share the same root.
1967 BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
1969 LPCSTR lpszStart;
1970 int dwLen;
1972 TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
1974 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootA(lpszPath1)))
1975 return FALSE;
1977 dwLen = PathCommonPrefixA(lpszPath1, lpszPath2, NULL) + 1;
1978 if (lpszStart - lpszPath1 > dwLen)
1979 return FALSE; /* Paths not common up to length of the root */
1980 return TRUE;
1983 /*************************************************************************
1984 * PathIsSameRootW [SHLWAPI.@]
1986 * See PathIsSameRootA.
1988 BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
1990 LPCWSTR lpszStart;
1991 int dwLen;
1993 TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
1995 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootW(lpszPath1)))
1996 return FALSE;
1998 dwLen = PathCommonPrefixW(lpszPath1, lpszPath2, NULL) + 1;
1999 if (lpszStart - lpszPath1 > dwLen)
2000 return FALSE; /* Paths not common up to length of the root */
2001 return TRUE;
2004 /*************************************************************************
2005 * PathIsContentTypeA [SHLWAPI.@]
2007 * Determine if a file is of a given registered content type.
2009 * PARAMS
2010 * lpszPath [I] File to check
2011 * lpszContentType [I] Content type to check for
2013 * RETURNS
2014 * TRUE If lpszPath is a given registered content type,
2015 * FALSE Otherwise.
2017 * NOTES
2018 * This function looks up the registered content type for lpszPath. If
2019 * a content type is registered, it is compared (case insensitively) to
2020 * lpszContentType. Only if this matches does the function succeed.
2022 BOOL WINAPI PathIsContentTypeA(LPCSTR lpszPath, LPCSTR lpszContentType)
2024 LPCSTR szExt;
2025 DWORD dwDummy;
2026 char szBuff[MAX_PATH];
2028 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszContentType));
2030 if (lpszPath && (szExt = PathFindExtensionA(lpszPath)) && *szExt &&
2031 !SHGetValueA(HKEY_CLASSES_ROOT, szExt, "Content Type",
2032 REG_NONE, szBuff, &dwDummy) &&
2033 !strcasecmp(lpszContentType, szBuff))
2035 return TRUE;
2037 return FALSE;
2040 /*************************************************************************
2041 * PathIsContentTypeW [SHLWAPI.@]
2043 * See PathIsContentTypeA.
2045 BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
2047 static const WCHAR szContentType[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2048 LPCWSTR szExt;
2049 DWORD dwDummy;
2050 WCHAR szBuff[MAX_PATH];
2052 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
2054 if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
2055 !SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
2056 REG_NONE, szBuff, &dwDummy) &&
2057 !strcmpiW(lpszContentType, szBuff))
2059 return TRUE;
2061 return FALSE;
2064 /*************************************************************************
2065 * PathIsFileSpecA [SHLWAPI.@]
2067 * Determine if a path is a file specification.
2069 * PARAMS
2070 * lpszPath [I] Path to check
2072 * RETURNS
2073 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2074 * FALSE Otherwise.
2076 BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
2078 TRACE("(%s)\n", debugstr_a(lpszPath));
2080 if (!lpszPath)
2081 return FALSE;
2083 while (*lpszPath)
2085 if (*lpszPath == '\\' || *lpszPath == ':')
2086 return FALSE;
2087 lpszPath = CharNextA(lpszPath);
2089 return TRUE;
2092 /*************************************************************************
2093 * PathIsFileSpecW [SHLWAPI.@]
2095 * See PathIsFileSpecA.
2097 BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
2099 TRACE("(%s)\n", debugstr_w(lpszPath));
2101 if (!lpszPath)
2102 return FALSE;
2104 while (*lpszPath)
2106 if (*lpszPath == '\\' || *lpszPath == ':')
2107 return FALSE;
2108 lpszPath++;
2110 return TRUE;
2113 /*************************************************************************
2114 * PathIsPrefixA [SHLWAPI.@]
2116 * Determine if a path is a prefix of another.
2118 * PARAMS
2119 * lpszPrefix [I] Prefix
2120 * lpszPath [I] Path to check
2122 * RETURNS
2123 * TRUE If lpszPath has lpszPrefix as its prefix,
2124 * FALSE If either path is NULL or lpszPrefix is not a prefix
2126 BOOL WINAPI PathIsPrefixA (LPCSTR lpszPrefix, LPCSTR lpszPath)
2128 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix), debugstr_a(lpszPath));
2130 if (lpszPrefix && lpszPath &&
2131 PathCommonPrefixA(lpszPath, lpszPrefix, NULL) == (int)strlen(lpszPrefix))
2132 return TRUE;
2133 return FALSE;
2136 /*************************************************************************
2137 * PathIsPrefixW [SHLWAPI.@]
2139 * See PathIsPrefixA.
2141 BOOL WINAPI PathIsPrefixW(LPCWSTR lpszPrefix, LPCWSTR lpszPath)
2143 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix), debugstr_w(lpszPath));
2145 if (lpszPrefix && lpszPath &&
2146 PathCommonPrefixW(lpszPath, lpszPrefix, NULL) == (int)strlenW(lpszPrefix))
2147 return TRUE;
2148 return FALSE;
2151 /*************************************************************************
2152 * PathIsSystemFolderA [SHLWAPI.@]
2154 * Determine if a path or file attributes are a system folder.
2156 * PARAMS
2157 * lpszPath [I] Path to check.
2158 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2160 * RETURNS
2161 * TRUE If lpszPath or dwAttrib are a system folder.
2162 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2164 BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
2166 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath), dwAttrib);
2168 if (lpszPath && *lpszPath)
2169 dwAttrib = GetFileAttributesA(lpszPath);
2171 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2172 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2173 return FALSE;
2174 return TRUE;
2177 /*************************************************************************
2178 * PathIsSystemFolderW [SHLWAPI.@]
2180 * See PathIsSystemFolderA.
2182 BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
2184 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath), dwAttrib);
2186 if (lpszPath && *lpszPath)
2187 dwAttrib = GetFileAttributesW(lpszPath);
2189 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2190 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2191 return FALSE;
2192 return TRUE;
2195 /*************************************************************************
2196 * PathIsUNCA [SHLWAPI.@]
2198 * Determine if a path is in UNC format.
2200 * PARAMS
2201 * lpszPath [I] Path to check
2203 * RETURNS
2204 * TRUE: The path is UNC.
2205 * FALSE: The path is not UNC or is NULL.
2207 BOOL WINAPI PathIsUNCA(LPCSTR lpszPath)
2209 TRACE("(%s)\n",debugstr_a(lpszPath));
2211 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2212 return TRUE;
2213 return FALSE;
2216 /*************************************************************************
2217 * PathIsUNCW [SHLWAPI.@]
2219 * See PathIsUNCA.
2221 BOOL WINAPI PathIsUNCW(LPCWSTR lpszPath)
2223 TRACE("(%s)\n",debugstr_w(lpszPath));
2225 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2226 return TRUE;
2227 return FALSE;
2230 /*************************************************************************
2231 * PathIsUNCServerA [SHLWAPI.@]
2233 * Determine if a path is a UNC server name ("\\SHARENAME").
2235 * PARAMS
2236 * lpszPath [I] Path to check.
2238 * RETURNS
2239 * TRUE If lpszPath is a valid UNC server name.
2240 * FALSE Otherwise.
2242 * NOTES
2243 * This routine is bug compatible with Win32: Server names with a
2244 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2245 * Fixing this bug may break other shlwapi functions!
2247 BOOL WINAPI PathIsUNCServerA(LPCSTR lpszPath)
2249 TRACE("(%s)\n", debugstr_a(lpszPath));
2251 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2253 while (*lpszPath)
2255 if (*lpszPath == '\\')
2256 return FALSE;
2257 lpszPath = CharNextA(lpszPath);
2259 return TRUE;
2261 return FALSE;
2264 /*************************************************************************
2265 * PathIsUNCServerW [SHLWAPI.@]
2267 * See PathIsUNCServerA.
2269 BOOL WINAPI PathIsUNCServerW(LPCWSTR lpszPath)
2271 TRACE("(%s)\n", debugstr_w(lpszPath));
2273 if (lpszPath && lpszPath[0] == '\\' && lpszPath[1] == '\\')
2275 return !strchrW( lpszPath + 2, '\\' );
2277 return FALSE;
2280 /*************************************************************************
2281 * PathIsUNCServerShareA [SHLWAPI.@]
2283 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2285 * PARAMS
2286 * lpszPath [I] Path to check.
2288 * RETURNS
2289 * TRUE If lpszPath is a valid UNC server share.
2290 * FALSE Otherwise.
2292 * NOTES
2293 * This routine is bug compatible with Win32: Server shares with a
2294 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2295 * Fixing this bug may break other shlwapi functions!
2297 BOOL WINAPI PathIsUNCServerShareA(LPCSTR lpszPath)
2299 TRACE("(%s)\n", debugstr_a(lpszPath));
2301 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2303 BOOL bSeenSlash = FALSE;
2304 while (*lpszPath)
2306 if (*lpszPath == '\\')
2308 if (bSeenSlash)
2309 return FALSE;
2310 bSeenSlash = TRUE;
2312 lpszPath = CharNextA(lpszPath);
2314 return bSeenSlash;
2316 return FALSE;
2319 /*************************************************************************
2320 * PathIsUNCServerShareW [SHLWAPI.@]
2322 * See PathIsUNCServerShareA.
2324 BOOL WINAPI PathIsUNCServerShareW(LPCWSTR lpszPath)
2326 TRACE("(%s)\n", debugstr_w(lpszPath));
2328 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2330 BOOL bSeenSlash = FALSE;
2331 while (*lpszPath)
2333 if (*lpszPath == '\\')
2335 if (bSeenSlash)
2336 return FALSE;
2337 bSeenSlash = TRUE;
2339 lpszPath++;
2341 return bSeenSlash;
2343 return FALSE;
2346 /*************************************************************************
2347 * PathCanonicalizeA [SHLWAPI.@]
2349 * Convert a path to its canonical form.
2351 * PARAMS
2352 * lpszBuf [O] Output path
2353 * lpszPath [I] Path to canonicalize
2355 * RETURNS
2356 * Success: TRUE. lpszBuf contains the output path,
2357 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2359 BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
2361 BOOL bRet = FALSE;
2363 TRACE("(%p,%s)\n", lpszBuf, debugstr_a(lpszPath));
2365 if (lpszBuf)
2366 *lpszBuf = '\0';
2368 if (!lpszBuf || !lpszPath)
2369 SetLastError(ERROR_INVALID_PARAMETER);
2370 else
2372 WCHAR szPath[MAX_PATH];
2373 WCHAR szBuff[MAX_PATH];
2374 int ret = MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
2376 if (!ret) {
2377 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2378 return FALSE;
2380 bRet = PathCanonicalizeW(szBuff, szPath);
2381 WideCharToMultiByte(CP_ACP,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
2383 return bRet;
2387 /*************************************************************************
2388 * PathCanonicalizeW [SHLWAPI.@]
2390 * See PathCanonicalizeA.
2392 BOOL WINAPI PathCanonicalizeW(LPWSTR lpszBuf, LPCWSTR lpszPath)
2394 LPWSTR lpszDst = lpszBuf;
2395 LPCWSTR lpszSrc = lpszPath;
2397 TRACE("(%p,%s)\n", lpszBuf, debugstr_w(lpszPath));
2399 if (lpszBuf)
2400 *lpszDst = '\0';
2402 if (!lpszBuf || !lpszPath)
2404 SetLastError(ERROR_INVALID_PARAMETER);
2405 return FALSE;
2408 if (!*lpszPath)
2410 *lpszBuf++ = '\\';
2411 *lpszBuf = '\0';
2412 return TRUE;
2415 /* Copy path root */
2416 if (*lpszSrc == '\\')
2418 *lpszDst++ = *lpszSrc++;
2420 else if (*lpszSrc && lpszSrc[1] == ':')
2422 /* X:\ */
2423 *lpszDst++ = *lpszSrc++;
2424 *lpszDst++ = *lpszSrc++;
2425 if (*lpszSrc == '\\')
2426 *lpszDst++ = *lpszSrc++;
2429 /* Canonicalize the rest of the path */
2430 while (*lpszSrc)
2432 if (*lpszSrc == '.')
2434 if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
2436 lpszSrc += 2; /* Skip .\ */
2438 else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
2440 /* \.. backs up a directory, over the root if it has no \ following X:.
2441 * .. is ignored if it would remove a UNC server name or initial \\
2443 if (lpszDst != lpszBuf)
2445 *lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2446 if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
2447 (lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
2449 if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
2451 lpszDst -= 2;
2452 while (lpszDst > lpszBuf && *lpszDst != '\\')
2453 lpszDst--;
2454 if (*lpszDst == '\\')
2455 lpszDst++; /* Reset to last '\' */
2456 else
2457 lpszDst = lpszBuf; /* Start path again from new root */
2459 else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
2460 lpszDst -= 2;
2462 while (lpszDst > lpszBuf && *lpszDst != '\\')
2463 lpszDst--;
2464 if (lpszDst == lpszBuf)
2466 *lpszDst++ = '\\';
2467 lpszSrc++;
2470 lpszSrc += 2; /* Skip .. in src path */
2472 else
2473 *lpszDst++ = *lpszSrc++;
2475 else
2476 *lpszDst++ = *lpszSrc++;
2478 /* Append \ to naked drive specs */
2479 if (lpszDst - lpszBuf == 2 && lpszDst[-1] == ':')
2480 *lpszDst++ = '\\';
2481 *lpszDst++ = '\0';
2482 return TRUE;
2485 /*************************************************************************
2486 * PathFindNextComponentA [SHLWAPI.@]
2488 * Find the next component in a path.
2490 * PARAMS
2491 * lpszPath [I] Path to find next component in
2493 * RETURNS
2494 * Success: A pointer to the next component, or the end of the string.
2495 * Failure: NULL, If lpszPath is invalid
2497 * NOTES
2498 * A 'component' is either a backslash character (\) or UNC marker (\\).
2499 * Because of this, relative paths (e.g "c:foo") are regarded as having
2500 * only one component.
2502 LPSTR WINAPI PathFindNextComponentA(LPCSTR lpszPath)
2504 LPSTR lpszSlash;
2506 TRACE("(%s)\n", debugstr_a(lpszPath));
2508 if(!lpszPath || !*lpszPath)
2509 return NULL;
2511 if ((lpszSlash = StrChrA(lpszPath, '\\')))
2513 if (lpszSlash[1] == '\\')
2514 lpszSlash++;
2515 return lpszSlash + 1;
2517 return (LPSTR)lpszPath + strlen(lpszPath);
2520 /*************************************************************************
2521 * PathFindNextComponentW [SHLWAPI.@]
2523 * See PathFindNextComponentA.
2525 LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
2527 LPWSTR lpszSlash;
2529 TRACE("(%s)\n", debugstr_w(lpszPath));
2531 if(!lpszPath || !*lpszPath)
2532 return NULL;
2534 if ((lpszSlash = StrChrW(lpszPath, '\\')))
2536 if (lpszSlash[1] == '\\')
2537 lpszSlash++;
2538 return lpszSlash + 1;
2540 return (LPWSTR)lpszPath + strlenW(lpszPath);
2543 /*************************************************************************
2544 * PathAddExtensionA [SHLWAPI.@]
2546 * Add a file extension to a path
2548 * PARAMS
2549 * lpszPath [I/O] Path to add extension to
2550 * lpszExtension [I] Extension to add to lpszPath
2552 * RETURNS
2553 * TRUE If the path was modified,
2554 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2555 * extension already, or the new path length is too big.
2557 * FIXME
2558 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2559 * does not do this, so the behaviour was removed.
2561 BOOL WINAPI PathAddExtensionA(LPSTR lpszPath, LPCSTR lpszExtension)
2563 size_t dwLen;
2565 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExtension));
2567 if (!lpszPath || !lpszExtension || *(PathFindExtensionA(lpszPath)))
2568 return FALSE;
2570 dwLen = strlen(lpszPath);
2572 if (dwLen + strlen(lpszExtension) >= MAX_PATH)
2573 return FALSE;
2575 strcpy(lpszPath + dwLen, lpszExtension);
2576 return TRUE;
2579 /*************************************************************************
2580 * PathAddExtensionW [SHLWAPI.@]
2582 * See PathAddExtensionA.
2584 BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
2586 size_t dwLen;
2588 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExtension));
2590 if (!lpszPath || !lpszExtension || *(PathFindExtensionW(lpszPath)))
2591 return FALSE;
2593 dwLen = strlenW(lpszPath);
2595 if (dwLen + strlenW(lpszExtension) >= MAX_PATH)
2596 return FALSE;
2598 strcpyW(lpszPath + dwLen, lpszExtension);
2599 return TRUE;
2602 /*************************************************************************
2603 * PathMakePrettyA [SHLWAPI.@]
2605 * Convert an uppercase DOS filename into lowercase.
2607 * PARAMS
2608 * lpszPath [I/O] Path to convert.
2610 * RETURNS
2611 * TRUE If the path was an uppercase DOS path and was converted,
2612 * FALSE Otherwise.
2614 BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
2616 LPSTR pszIter = lpszPath;
2618 TRACE("(%s)\n", debugstr_a(lpszPath));
2620 if (!pszIter)
2621 return FALSE;
2623 if (*pszIter)
2627 if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
2628 return FALSE; /* Not DOS path */
2629 pszIter++;
2630 } while (*pszIter);
2631 pszIter = lpszPath + 1;
2632 while (*pszIter)
2634 *pszIter = tolower(*pszIter);
2635 pszIter++;
2638 return TRUE;
2641 /*************************************************************************
2642 * PathMakePrettyW [SHLWAPI.@]
2644 * See PathMakePrettyA.
2646 BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
2648 LPWSTR pszIter = lpszPath;
2650 TRACE("(%s)\n", debugstr_w(lpszPath));
2652 if (!pszIter)
2653 return FALSE;
2655 if (*pszIter)
2659 if (islowerW(*pszIter))
2660 return FALSE; /* Not DOS path */
2661 pszIter++;
2662 } while (*pszIter);
2663 pszIter = lpszPath + 1;
2664 while (*pszIter)
2666 *pszIter = tolowerW(*pszIter);
2667 pszIter++;
2670 return TRUE;
2673 /*************************************************************************
2674 * PathCommonPrefixA [SHLWAPI.@]
2676 * Determine the length of the common prefix between two paths.
2678 * PARAMS
2679 * lpszFile1 [I] First path for comparison
2680 * lpszFile2 [I] Second path for comparison
2681 * achPath [O] Destination for common prefix string
2683 * RETURNS
2684 * The length of the common prefix. This is 0 if there is no common
2685 * prefix between the paths or if any parameters are invalid. If the prefix
2686 * is non-zero and achPath is not NULL, achPath is filled with the common
2687 * part of the prefix and NUL terminated.
2689 * NOTES
2690 * A common prefix of 2 is always returned as 3. It is thus possible for
2691 * the length returned to be invalid (i.e. Longer than one or both of the
2692 * strings given as parameters). This Win32 behaviour has been implemented
2693 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2694 * To work around this when using this function, always check that the byte
2695 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2697 int WINAPI PathCommonPrefixA(LPCSTR lpszFile1, LPCSTR lpszFile2, LPSTR achPath)
2699 size_t iLen = 0;
2700 LPCSTR lpszIter1 = lpszFile1;
2701 LPCSTR lpszIter2 = lpszFile2;
2703 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1), debugstr_a(lpszFile2), achPath);
2705 if (achPath)
2706 *achPath = '\0';
2708 if (!lpszFile1 || !lpszFile2)
2709 return 0;
2711 /* Handle roots first */
2712 if (PathIsUNCA(lpszFile1))
2714 if (!PathIsUNCA(lpszFile2))
2715 return 0;
2716 lpszIter1 += 2;
2717 lpszIter2 += 2;
2719 else if (PathIsUNCA(lpszFile2))
2720 return 0; /* Know already lpszFile1 is not UNC */
2724 /* Update len */
2725 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2726 (!*lpszIter2 || *lpszIter2 == '\\'))
2727 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2729 if (!*lpszIter1 || (tolower(*lpszIter1) != tolower(*lpszIter2)))
2730 break; /* Strings differ at this point */
2732 lpszIter1++;
2733 lpszIter2++;
2734 } while (1);
2736 if (iLen == 2)
2737 iLen++; /* Feature/Bug compatible with Win32 */
2739 if (iLen && achPath)
2741 memcpy(achPath,lpszFile1,iLen);
2742 achPath[iLen] = '\0';
2744 return iLen;
2747 /*************************************************************************
2748 * PathCommonPrefixW [SHLWAPI.@]
2750 * See PathCommonPrefixA.
2752 int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
2754 size_t iLen = 0;
2755 LPCWSTR lpszIter1 = lpszFile1;
2756 LPCWSTR lpszIter2 = lpszFile2;
2758 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1), debugstr_w(lpszFile2), achPath);
2760 if (achPath)
2761 *achPath = '\0';
2763 if (!lpszFile1 || !lpszFile2)
2764 return 0;
2766 /* Handle roots first */
2767 if (PathIsUNCW(lpszFile1))
2769 if (!PathIsUNCW(lpszFile2))
2770 return 0;
2771 lpszIter1 += 2;
2772 lpszIter2 += 2;
2774 else if (PathIsUNCW(lpszFile2))
2775 return 0; /* Know already lpszFile1 is not UNC */
2779 /* Update len */
2780 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2781 (!*lpszIter2 || *lpszIter2 == '\\'))
2782 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2784 if (!*lpszIter1 || (tolowerW(*lpszIter1) != tolowerW(*lpszIter2)))
2785 break; /* Strings differ at this point */
2787 lpszIter1++;
2788 lpszIter2++;
2789 } while (1);
2791 if (iLen == 2)
2792 iLen++; /* Feature/Bug compatible with Win32 */
2794 if (iLen && achPath)
2796 memcpy(achPath,lpszFile1,iLen * sizeof(WCHAR));
2797 achPath[iLen] = '\0';
2799 return iLen;
2802 /*************************************************************************
2803 * PathCompactPathA [SHLWAPI.@]
2805 * Make a path fit into a given width when printed to a DC.
2807 * PARAMS
2808 * hDc [I] Destination DC
2809 * lpszPath [I/O] Path to be printed to hDc
2810 * dx [I] Desired width
2812 * RETURNS
2813 * TRUE If the path was modified/went well.
2814 * FALSE Otherwise.
2816 BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
2818 BOOL bRet = FALSE;
2820 TRACE("(%p,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
2822 if (lpszPath)
2824 WCHAR szPath[MAX_PATH];
2825 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
2826 bRet = PathCompactPathW(hDC, szPath, dx);
2827 WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
2829 return bRet;
2832 /*************************************************************************
2833 * PathCompactPathW [SHLWAPI.@]
2835 * See PathCompactPathA.
2837 BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
2839 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
2840 BOOL bRet = TRUE;
2841 HDC hdc = 0;
2842 WCHAR buff[MAX_PATH];
2843 SIZE size;
2844 DWORD dwLen;
2846 TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
2848 if (!lpszPath)
2849 return FALSE;
2851 if (!hDC)
2852 hdc = hDC = GetDC(0);
2854 /* Get the length of the whole path */
2855 dwLen = strlenW(lpszPath);
2856 GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
2858 if ((UINT)size.cx > dx)
2860 /* Path too big, must reduce it */
2861 LPWSTR sFile;
2862 DWORD dwEllipsesLen = 0, dwPathLen = 0;
2864 sFile = PathFindFileNameW(lpszPath);
2865 if (sFile != lpszPath) sFile--;
2867 /* Get the size of ellipses */
2868 GetTextExtentPointW(hDC, szEllipses, 3, &size);
2869 dwEllipsesLen = size.cx;
2870 /* Get the size of the file name */
2871 GetTextExtentPointW(hDC, sFile, strlenW(sFile), &size);
2872 dwPathLen = size.cx;
2874 if (sFile != lpszPath)
2876 LPWSTR sPath = sFile;
2877 BOOL bEllipses = FALSE;
2879 /* The path includes a file name. Include as much of the path prior to
2880 * the file name as possible, allowing for the ellipses, e.g:
2881 * c:\some very long path\filename ==> c:\some v...\filename
2883 lstrcpynW(buff, sFile, MAX_PATH);
2887 DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
2889 GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
2890 dwTotalLen += size.cx;
2891 if (dwTotalLen <= dx)
2892 break;
2893 sPath--;
2894 if (!bEllipses)
2896 bEllipses = TRUE;
2897 sPath -= 2;
2899 } while (sPath > lpszPath);
2901 if (sPath > lpszPath)
2903 if (bEllipses)
2905 strcpyW(sPath, szEllipses);
2906 strcpyW(sPath+3, buff);
2908 bRet = TRUE;
2909 goto end;
2911 strcpyW(lpszPath, szEllipses);
2912 strcpyW(lpszPath+3, buff);
2913 bRet = FALSE;
2914 goto end;
2917 /* Trim the path by adding ellipses to the end, e.g:
2918 * A very long file name.txt ==> A very...
2920 dwLen = strlenW(lpszPath);
2922 if (dwLen > MAX_PATH - 3)
2923 dwLen = MAX_PATH - 3;
2924 lstrcpynW(buff, sFile, dwLen);
2926 do {
2927 dwLen--;
2928 GetTextExtentPointW(hDC, buff, dwLen, &size);
2929 } while (dwLen && size.cx + dwEllipsesLen > dx);
2931 if (!dwLen)
2933 DWORD dwWritten = 0;
2935 dwEllipsesLen /= 3; /* Size of a single '.' */
2937 /* Write as much of the Ellipses string as possible */
2938 while (dwWritten + dwEllipsesLen < dx && dwLen < 3)
2940 *lpszPath++ = '.';
2941 dwWritten += dwEllipsesLen;
2942 dwLen++;
2944 *lpszPath = '\0';
2945 bRet = FALSE;
2947 else
2949 strcpyW(buff + dwLen, szEllipses);
2950 strcpyW(lpszPath, buff);
2954 end:
2955 if (hdc)
2956 ReleaseDC(0, hdc);
2958 return bRet;
2961 /*************************************************************************
2962 * PathGetCharTypeA [SHLWAPI.@]
2964 * Categorise a character from a file path.
2966 * PARAMS
2967 * ch [I] Character to get the type of
2969 * RETURNS
2970 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2972 UINT WINAPI PathGetCharTypeA(UCHAR ch)
2974 return PathGetCharTypeW(ch);
2977 /*************************************************************************
2978 * PathGetCharTypeW [SHLWAPI.@]
2980 * See PathGetCharTypeA.
2982 UINT WINAPI PathGetCharTypeW(WCHAR ch)
2984 UINT flags = 0;
2986 TRACE("(%d)\n", ch);
2988 if (!ch || ch < ' ' || ch == '<' || ch == '>' ||
2989 ch == '"' || ch == '|' || ch == '/')
2990 flags = GCT_INVALID; /* Invalid */
2991 else if (ch == '*' || ch=='?')
2992 flags = GCT_WILD; /* Wildchars */
2993 else if ((ch == '\\') || (ch == ':'))
2994 return GCT_SEPARATOR; /* Path separators */
2995 else
2997 if (ch < 126)
2999 if (((ch & 0x1) && ch != ';') || !ch || isalnum(ch) || ch == '$' || ch == '&' || ch == '(' ||
3000 ch == '.' || ch == '@' || ch == '^' ||
3001 ch == '\'' || ch == 130 || ch == '`')
3002 flags |= GCT_SHORTCHAR; /* All these are valid for DOS */
3004 else
3005 flags |= GCT_SHORTCHAR; /* Bug compatible with win32 */
3006 flags |= GCT_LFNCHAR; /* Valid for long file names */
3008 return flags;
3011 /*************************************************************************
3012 * SHLWAPI_UseSystemForSystemFolders
3014 * Internal helper for PathMakeSystemFolderW.
3016 static BOOL SHLWAPI_UseSystemForSystemFolders(void)
3018 static BOOL bCheckedReg = FALSE;
3019 static BOOL bUseSystemForSystemFolders = FALSE;
3021 if (!bCheckedReg)
3023 bCheckedReg = TRUE;
3025 /* Key tells Win what file attributes to use on system folders */
3026 if (SHGetValueA(HKEY_LOCAL_MACHINE,
3027 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3028 "UseSystemForSystemFolders", 0, 0, 0))
3029 bUseSystemForSystemFolders = TRUE;
3031 return bUseSystemForSystemFolders;
3034 /*************************************************************************
3035 * PathMakeSystemFolderA [SHLWAPI.@]
3037 * Set system folder attribute for a path.
3039 * PARAMS
3040 * lpszPath [I] The path to turn into a system folder
3042 * RETURNS
3043 * TRUE If the path was changed to/already was a system folder
3044 * FALSE If the path is invalid or SetFileAttributesA() fails
3046 BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
3048 BOOL bRet = FALSE;
3050 TRACE("(%s)\n", debugstr_a(lpszPath));
3052 if (lpszPath && *lpszPath)
3054 WCHAR szPath[MAX_PATH];
3055 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
3056 bRet = PathMakeSystemFolderW(szPath);
3058 return bRet;
3061 /*************************************************************************
3062 * PathMakeSystemFolderW [SHLWAPI.@]
3064 * See PathMakeSystemFolderA.
3066 BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
3068 DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
3069 WCHAR buff[MAX_PATH];
3071 TRACE("(%s)\n", debugstr_w(lpszPath));
3073 if (!lpszPath || !*lpszPath)
3074 return FALSE;
3076 /* If the directory is already a system directory, don't do anything */
3077 GetSystemDirectoryW(buff, MAX_PATH);
3078 if (!strcmpW(buff, lpszPath))
3079 return TRUE;
3081 GetWindowsDirectoryW(buff, MAX_PATH);
3082 if (!strcmpW(buff, lpszPath))
3083 return TRUE;
3085 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3086 if (SHLWAPI_UseSystemForSystemFolders())
3087 dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
3089 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
3090 return FALSE;
3092 /* Change file attributes to system attributes */
3093 dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
3094 return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
3097 /*************************************************************************
3098 * PathRenameExtensionA [SHLWAPI.@]
3100 * Swap the file extension in a path with another extension.
3102 * PARAMS
3103 * lpszPath [I/O] Path to swap the extension in
3104 * lpszExt [I] The new extension
3106 * RETURNS
3107 * TRUE if lpszPath was modified,
3108 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3110 BOOL WINAPI PathRenameExtensionA(LPSTR lpszPath, LPCSTR lpszExt)
3112 LPSTR lpszExtension;
3114 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExt));
3116 lpszExtension = PathFindExtensionA(lpszPath);
3118 if (!lpszExtension || (lpszExtension - lpszPath + strlen(lpszExt) >= MAX_PATH))
3119 return FALSE;
3121 strcpy(lpszExtension, lpszExt);
3122 return TRUE;
3125 /*************************************************************************
3126 * PathRenameExtensionW [SHLWAPI.@]
3128 * See PathRenameExtensionA.
3130 BOOL WINAPI PathRenameExtensionW(LPWSTR lpszPath, LPCWSTR lpszExt)
3132 LPWSTR lpszExtension;
3134 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExt));
3136 lpszExtension = PathFindExtensionW(lpszPath);
3138 if (!lpszExtension || (lpszExtension - lpszPath + strlenW(lpszExt) >= MAX_PATH))
3139 return FALSE;
3141 strcpyW(lpszExtension, lpszExt);
3142 return TRUE;
3145 /*************************************************************************
3146 * PathSearchAndQualifyA [SHLWAPI.@]
3148 * Determine if a given path is correct and fully qualified.
3150 * PARAMS
3151 * lpszPath [I] Path to check
3152 * lpszBuf [O] Output for correct path
3153 * cchBuf [I] Size of lpszBuf
3155 * RETURNS
3156 * Unknown.
3158 BOOL WINAPI PathSearchAndQualifyA(LPCSTR lpszPath, LPSTR lpszBuf, UINT cchBuf)
3160 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
3162 if(SearchPathA(NULL, lpszPath, NULL, cchBuf, lpszBuf, NULL))
3163 return TRUE;
3164 return !!GetFullPathNameA(lpszPath, cchBuf, lpszBuf, NULL);
3167 /*************************************************************************
3168 * PathSearchAndQualifyW [SHLWAPI.@]
3170 * See PathSearchAndQualifyA.
3172 BOOL WINAPI PathSearchAndQualifyW(LPCWSTR lpszPath, LPWSTR lpszBuf, UINT cchBuf)
3174 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
3176 if(SearchPathW(NULL, lpszPath, NULL, cchBuf, lpszBuf, NULL))
3177 return TRUE;
3178 return !!GetFullPathNameW(lpszPath, cchBuf, lpszBuf, NULL);
3181 /*************************************************************************
3182 * PathSkipRootA [SHLWAPI.@]
3184 * Return the portion of a path following the drive letter or mount point.
3186 * PARAMS
3187 * lpszPath [I] The path to skip on
3189 * RETURNS
3190 * Success: A pointer to the next character after the root.
3191 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3193 LPSTR WINAPI PathSkipRootA(LPCSTR lpszPath)
3195 TRACE("(%s)\n", debugstr_a(lpszPath));
3197 if (!lpszPath || !*lpszPath)
3198 return NULL;
3200 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3202 /* Network share: skip share server and mount point */
3203 lpszPath += 2;
3204 if ((lpszPath = StrChrA(lpszPath, '\\')) &&
3205 (lpszPath = StrChrA(lpszPath + 1, '\\')))
3206 lpszPath++;
3207 return (LPSTR)lpszPath;
3210 if (IsDBCSLeadByte(*lpszPath))
3211 return NULL;
3213 /* Check x:\ */
3214 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3215 return (LPSTR)lpszPath + 3;
3216 return NULL;
3219 /*************************************************************************
3220 * PathSkipRootW [SHLWAPI.@]
3222 * See PathSkipRootA.
3224 LPWSTR WINAPI PathSkipRootW(LPCWSTR lpszPath)
3226 TRACE("(%s)\n", debugstr_w(lpszPath));
3228 if (!lpszPath || !*lpszPath)
3229 return NULL;
3231 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3233 /* Network share: skip share server and mount point */
3234 lpszPath += 2;
3235 if ((lpszPath = StrChrW(lpszPath, '\\')) &&
3236 (lpszPath = StrChrW(lpszPath + 1, '\\')))
3237 lpszPath++;
3238 return (LPWSTR)lpszPath;
3241 /* Check x:\ */
3242 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3243 return (LPWSTR)lpszPath + 3;
3244 return NULL;
3247 /*************************************************************************
3248 * PathCreateFromUrlA [SHLWAPI.@]
3250 * See PathCreateFromUrlW
3252 HRESULT WINAPI PathCreateFromUrlA(LPCSTR pszUrl, LPSTR pszPath,
3253 LPDWORD pcchPath, DWORD dwReserved)
3255 WCHAR bufW[MAX_PATH];
3256 WCHAR *pathW = bufW;
3257 UNICODE_STRING urlW;
3258 HRESULT ret;
3259 DWORD lenW = sizeof(bufW)/sizeof(WCHAR), lenA;
3261 if (!pszUrl || !pszPath || !pcchPath || !*pcchPath)
3262 return E_INVALIDARG;
3264 if(!RtlCreateUnicodeStringFromAsciiz(&urlW, pszUrl))
3265 return E_INVALIDARG;
3266 if((ret = PathCreateFromUrlW(urlW.Buffer, pathW, &lenW, dwReserved)) == E_POINTER) {
3267 pathW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
3268 ret = PathCreateFromUrlW(urlW.Buffer, pathW, &lenW, dwReserved);
3270 if(ret == S_OK) {
3271 RtlUnicodeToMultiByteSize(&lenA, pathW, lenW * sizeof(WCHAR));
3272 if(*pcchPath > lenA) {
3273 RtlUnicodeToMultiByteN(pszPath, *pcchPath - 1, &lenA, pathW, lenW * sizeof(WCHAR));
3274 pszPath[lenA] = 0;
3275 *pcchPath = lenA;
3276 } else {
3277 *pcchPath = lenA + 1;
3278 ret = E_POINTER;
3281 if(pathW != bufW) HeapFree(GetProcessHeap(), 0, pathW);
3282 RtlFreeUnicodeString(&urlW);
3283 return ret;
3286 /*************************************************************************
3287 * PathCreateFromUrlW [SHLWAPI.@]
3289 * Create a path from a URL
3291 * PARAMS
3292 * lpszUrl [I] URL to convert into a path
3293 * lpszPath [O] Output buffer for the resulting Path
3294 * pcchPath [I] Length of lpszPath
3295 * dwFlags [I] Flags controlling the conversion
3297 * RETURNS
3298 * Success: S_OK. lpszPath contains the URL in path format,
3299 * Failure: An HRESULT error code such as E_INVALIDARG.
3301 HRESULT WINAPI PathCreateFromUrlW(LPCWSTR pszUrl, LPWSTR pszPath,
3302 LPDWORD pcchPath, DWORD dwReserved)
3304 static const WCHAR file_colon[] = { 'f','i','l','e',':',0 };
3305 static const WCHAR localhost[] = { 'l','o','c','a','l','h','o','s','t',0 };
3306 DWORD nslashes, unescape, len;
3307 const WCHAR *src;
3308 WCHAR *tpath, *dst;
3309 HRESULT ret;
3311 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl), pszPath, pcchPath, dwReserved);
3313 if (!pszUrl || !pszPath || !pcchPath || !*pcchPath)
3314 return E_INVALIDARG;
3316 if (lstrlenW(pszUrl) < 5)
3317 return E_INVALIDARG;
3319 if (CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pszUrl, 5,
3320 file_colon, 5) != CSTR_EQUAL)
3321 return E_INVALIDARG;
3322 pszUrl += 5;
3323 ret = S_OK;
3325 src = pszUrl;
3326 nslashes = 0;
3327 while (*src == '/' || *src == '\\') {
3328 nslashes++;
3329 src++;
3332 /* We need a temporary buffer so we can compute what size to ask for.
3333 * We know that the final string won't be longer than the current pszUrl
3334 * plus at most two backslashes. All the other transformations make it
3335 * shorter.
3337 len = 2 + lstrlenW(pszUrl) + 1;
3338 if (*pcchPath < len)
3339 tpath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3340 else
3341 tpath = pszPath;
3343 len = 0;
3344 dst = tpath;
3345 unescape = 1;
3346 switch (nslashes)
3348 case 0:
3349 /* 'file:' + escaped DOS path */
3350 break;
3351 case 1:
3352 /* 'file:/' + escaped DOS path */
3353 /* fall through */
3354 case 3:
3355 /* 'file:///' (implied localhost) + escaped DOS path */
3356 if (!isalphaW(*src) || (src[1] != ':' && src[1] != '|'))
3357 src -= 1;
3358 break;
3359 case 2:
3360 if (lstrlenW(src) >= 10 && CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
3361 src, 9, localhost, 9) == CSTR_EQUAL && (src[9] == '/' || src[9] == '\\'))
3363 /* 'file://localhost/' + escaped DOS path */
3364 src += 10;
3366 else if (isalphaW(*src) && (src[1] == ':' || src[1] == '|'))
3368 /* 'file://' + unescaped DOS path */
3369 unescape = 0;
3371 else
3373 /* 'file://hostname:port/path' (where path is escaped)
3374 * or 'file:' + escaped UNC path (\\server\share\path)
3375 * The second form is clearly specific to Windows and it might
3376 * even be doing a network lookup to try to figure it out.
3378 while (*src && *src != '/' && *src != '\\')
3379 src++;
3380 len = src - pszUrl;
3381 StrCpyNW(dst, pszUrl, len + 1);
3382 dst += len;
3383 if (*src && isalphaW(src[1]) && (src[2] == ':' || src[2] == '|'))
3385 /* 'Forget' to add a trailing '/', just like Windows */
3386 src++;
3389 break;
3390 case 4:
3391 /* 'file://' + unescaped UNC path (\\server\share\path) */
3392 unescape = 0;
3393 if (isalphaW(*src) && (src[1] == ':' || src[1] == '|'))
3394 break;
3395 /* fall through */
3396 default:
3397 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3398 src -= 2;
3401 /* Copy the remainder of the path */
3402 len += lstrlenW(src);
3403 StrCpyW(dst, src);
3405 /* First do the Windows-specific path conversions */
3406 for (dst = tpath; *dst; dst++)
3407 if (*dst == '/') *dst = '\\';
3408 if (isalphaW(*tpath) && tpath[1] == '|')
3409 tpath[1] = ':'; /* c| -> c: */
3411 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3412 if (unescape)
3414 ret = UrlUnescapeW(tpath, NULL, &len, URL_UNESCAPE_INPLACE);
3415 if (ret == S_OK)
3417 /* When working in-place UrlUnescapeW() does not set len */
3418 len = lstrlenW(tpath);
3422 if (*pcchPath < len + 1)
3424 ret = E_POINTER;
3425 *pcchPath = len + 1;
3427 else
3429 *pcchPath = len;
3430 if (tpath != pszPath)
3431 StrCpyW(pszPath, tpath);
3433 if (tpath != pszPath)
3434 HeapFree(GetProcessHeap(), 0, tpath);
3436 TRACE("Returning (%u) %s\n", *pcchPath, debugstr_w(pszPath));
3437 return ret;
3440 /*************************************************************************
3441 * PathCreateFromUrlAlloc [SHLWAPI.@]
3443 HRESULT WINAPI PathCreateFromUrlAlloc(LPCWSTR pszUrl, LPWSTR *pszPath,
3444 DWORD dwReserved)
3446 WCHAR pathW[MAX_PATH];
3447 DWORD size;
3448 HRESULT hr;
3450 size = MAX_PATH;
3451 hr = PathCreateFromUrlW(pszUrl, pathW, &size, dwReserved);
3452 if (SUCCEEDED(hr))
3454 /* Yes, this is supposed to crash if pszPath is NULL */
3455 *pszPath = StrDupW(pathW);
3457 return hr;
3460 /*************************************************************************
3461 * PathRelativePathToA [SHLWAPI.@]
3463 * Create a relative path from one path to another.
3465 * PARAMS
3466 * lpszPath [O] Destination for relative path
3467 * lpszFrom [I] Source path
3468 * dwAttrFrom [I] File attribute of source path
3469 * lpszTo [I] Destination path
3470 * dwAttrTo [I] File attributes of destination path
3472 * RETURNS
3473 * TRUE If a relative path can be formed. lpszPath contains the new path
3474 * FALSE If the paths are not relative or any parameters are invalid
3476 * NOTES
3477 * lpszTo should be at least MAX_PATH in length.
3479 * Calling this function with relative paths for lpszFrom or lpszTo may
3480 * give erroneous results.
3482 * The Win32 version of this function contains a bug where the lpszTo string
3483 * may be referenced 1 byte beyond the end of the string. As a result random
3484 * garbage may be written to the output path, depending on what lies beyond
3485 * the last byte of the string. This bug occurs because of the behaviour of
3486 * PathCommonPrefix() (see notes for that function), and no workaround seems
3487 * possible with Win32.
3489 * This bug has been fixed here, so for example the relative path from "\\"
3490 * to "\\" is correctly determined as "." in this implementation.
3492 BOOL WINAPI PathRelativePathToA(LPSTR lpszPath, LPCSTR lpszFrom, DWORD dwAttrFrom,
3493 LPCSTR lpszTo, DWORD dwAttrTo)
3495 BOOL bRet = FALSE;
3497 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath, debugstr_a(lpszFrom),
3498 dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
3500 if(lpszPath && lpszFrom && lpszTo)
3502 WCHAR szPath[MAX_PATH];
3503 WCHAR szFrom[MAX_PATH];
3504 WCHAR szTo[MAX_PATH];
3505 MultiByteToWideChar(CP_ACP,0,lpszFrom,-1,szFrom,MAX_PATH);
3506 MultiByteToWideChar(CP_ACP,0,lpszTo,-1,szTo,MAX_PATH);
3507 bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
3508 WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
3510 return bRet;
3513 /*************************************************************************
3514 * PathRelativePathToW [SHLWAPI.@]
3516 * See PathRelativePathToA.
3518 BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrFrom,
3519 LPCWSTR lpszTo, DWORD dwAttrTo)
3521 static const WCHAR szPrevDirSlash[] = { '.', '.', '\\', '\0' };
3522 static const WCHAR szPrevDir[] = { '.', '.', '\0' };
3523 WCHAR szFrom[MAX_PATH];
3524 WCHAR szTo[MAX_PATH];
3525 DWORD dwLen;
3527 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath, debugstr_w(lpszFrom),
3528 dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
3530 if(!lpszPath || !lpszFrom || !lpszTo)
3531 return FALSE;
3533 *lpszPath = '\0';
3534 lstrcpynW(szFrom, lpszFrom, MAX_PATH);
3535 lstrcpynW(szTo, lpszTo, MAX_PATH);
3537 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3538 PathRemoveFileSpecW(szFrom);
3539 if(!(dwAttrTo & FILE_ATTRIBUTE_DIRECTORY))
3540 PathRemoveFileSpecW(szTo);
3542 /* Paths can only be relative if they have a common root */
3543 if(!(dwLen = PathCommonPrefixW(szFrom, szTo, 0)))
3544 return FALSE;
3546 /* Strip off lpszFrom components to the root, by adding "..\" */
3547 lpszFrom = szFrom + dwLen;
3548 if (!*lpszFrom)
3550 lpszPath[0] = '.';
3551 lpszPath[1] = '\0';
3553 if (*lpszFrom == '\\')
3554 lpszFrom++;
3556 while (*lpszFrom)
3558 lpszFrom = PathFindNextComponentW(lpszFrom);
3559 strcatW(lpszPath, *lpszFrom ? szPrevDirSlash : szPrevDir);
3562 /* From the root add the components of lpszTo */
3563 lpszTo += dwLen;
3564 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3565 * this function.
3567 if (*lpszTo && lpszTo[-1])
3569 if (*lpszTo != '\\')
3570 lpszTo--;
3571 dwLen = strlenW(lpszPath);
3572 if (dwLen + strlenW(lpszTo) >= MAX_PATH)
3574 *lpszPath = '\0';
3575 return FALSE;
3577 strcpyW(lpszPath + dwLen, lpszTo);
3579 return TRUE;
3582 /*************************************************************************
3583 * PathUnmakeSystemFolderA [SHLWAPI.@]
3585 * Remove the system folder attributes from a path.
3587 * PARAMS
3588 * lpszPath [I] The path to remove attributes from
3590 * RETURNS
3591 * Success: TRUE.
3592 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3593 * SetFileAttributesA() fails.
3595 BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
3597 DWORD dwAttr;
3599 TRACE("(%s)\n", debugstr_a(lpszPath));
3601 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3602 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3603 return FALSE;
3605 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3606 return SetFileAttributesA(lpszPath, dwAttr);
3609 /*************************************************************************
3610 * PathUnmakeSystemFolderW [SHLWAPI.@]
3612 * See PathUnmakeSystemFolderA.
3614 BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
3616 DWORD dwAttr;
3618 TRACE("(%s)\n", debugstr_w(lpszPath));
3620 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3621 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3622 return FALSE;
3624 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3625 return SetFileAttributesW(lpszPath, dwAttr);
3629 /*************************************************************************
3630 * PathSetDlgItemPathA [SHLWAPI.@]
3632 * Set the text of a dialog item to a path, shrinking the path to fit
3633 * if it is too big for the item.
3635 * PARAMS
3636 * hDlg [I] Dialog handle
3637 * id [I] ID of item in the dialog
3638 * lpszPath [I] Path to set as the items text
3640 * RETURNS
3641 * Nothing.
3643 * NOTES
3644 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3645 * window text is erased).
3647 VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
3649 WCHAR szPath[MAX_PATH];
3651 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
3653 if (lpszPath)
3654 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
3655 else
3656 szPath[0] = '\0';
3657 PathSetDlgItemPathW(hDlg, id, szPath);
3660 /*************************************************************************
3661 * PathSetDlgItemPathW [SHLWAPI.@]
3663 * See PathSetDlgItemPathA.
3665 VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
3667 WCHAR path[MAX_PATH + 1];
3668 HWND hwItem;
3669 RECT rect;
3670 HDC hdc;
3671 HGDIOBJ hPrevObj;
3673 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
3675 if (!(hwItem = GetDlgItem(hDlg, id)))
3676 return;
3678 if (lpszPath)
3679 lstrcpynW(path, lpszPath, sizeof(path) / sizeof(WCHAR));
3680 else
3681 path[0] = '\0';
3683 GetClientRect(hwItem, &rect);
3684 hdc = GetDC(hDlg);
3685 hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
3687 if (hPrevObj)
3689 PathCompactPathW(hdc, path, rect.right);
3690 SelectObject(hdc, hPrevObj);
3693 ReleaseDC(hDlg, hdc);
3694 SetWindowTextW(hwItem, path);
3697 /*************************************************************************
3698 * PathIsNetworkPathA [SHLWAPI.@]
3700 * Determine if the given path is a network path.
3702 * PARAMS
3703 * lpszPath [I] Path to check
3705 * RETURNS
3706 * TRUE If lpszPath is a UNC share or mapped network drive, or
3707 * FALSE If lpszPath is a local drive or cannot be determined
3709 BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
3711 int dwDriveNum;
3713 TRACE("(%s)\n",debugstr_a(lpszPath));
3715 if (!lpszPath)
3716 return FALSE;
3717 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3718 return TRUE;
3719 dwDriveNum = PathGetDriveNumberA(lpszPath);
3720 if (dwDriveNum == -1)
3721 return FALSE;
3722 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3723 return pIsNetDrive(dwDriveNum);
3726 /*************************************************************************
3727 * PathIsNetworkPathW [SHLWAPI.@]
3729 * See PathIsNetworkPathA.
3731 BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
3733 int dwDriveNum;
3735 TRACE("(%s)\n", debugstr_w(lpszPath));
3737 if (!lpszPath)
3738 return FALSE;
3739 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3740 return TRUE;
3741 dwDriveNum = PathGetDriveNumberW(lpszPath);
3742 if (dwDriveNum == -1)
3743 return FALSE;
3744 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3745 return pIsNetDrive(dwDriveNum);
3748 /*************************************************************************
3749 * PathIsLFNFileSpecA [SHLWAPI.@]
3751 * Determine if the given path is a long file name
3753 * PARAMS
3754 * lpszPath [I] Path to check
3756 * RETURNS
3757 * TRUE If path is a long file name,
3758 * FALSE If path is a valid DOS short file name
3760 BOOL WINAPI PathIsLFNFileSpecA(LPCSTR lpszPath)
3762 DWORD dwNameLen = 0, dwExtLen = 0;
3764 TRACE("(%s)\n",debugstr_a(lpszPath));
3766 if (!lpszPath)
3767 return FALSE;
3769 while (*lpszPath)
3771 if (*lpszPath == ' ')
3772 return TRUE; /* DOS names cannot have spaces */
3773 if (*lpszPath == '.')
3775 if (dwExtLen)
3776 return TRUE; /* DOS names have only one dot */
3777 dwExtLen = 1;
3779 else if (dwExtLen)
3781 dwExtLen++;
3782 if (dwExtLen > 4)
3783 return TRUE; /* DOS extensions are <= 3 chars*/
3785 else
3787 dwNameLen++;
3788 if (dwNameLen > 8)
3789 return TRUE; /* DOS names are <= 8 chars */
3791 lpszPath += IsDBCSLeadByte(*lpszPath) ? 2 : 1;
3793 return FALSE; /* Valid DOS path */
3796 /*************************************************************************
3797 * PathIsLFNFileSpecW [SHLWAPI.@]
3799 * See PathIsLFNFileSpecA.
3801 BOOL WINAPI PathIsLFNFileSpecW(LPCWSTR lpszPath)
3803 DWORD dwNameLen = 0, dwExtLen = 0;
3805 TRACE("(%s)\n",debugstr_w(lpszPath));
3807 if (!lpszPath)
3808 return FALSE;
3810 while (*lpszPath)
3812 if (*lpszPath == ' ')
3813 return TRUE; /* DOS names cannot have spaces */
3814 if (*lpszPath == '.')
3816 if (dwExtLen)
3817 return TRUE; /* DOS names have only one dot */
3818 dwExtLen = 1;
3820 else if (dwExtLen)
3822 dwExtLen++;
3823 if (dwExtLen > 4)
3824 return TRUE; /* DOS extensions are <= 3 chars*/
3826 else
3828 dwNameLen++;
3829 if (dwNameLen > 8)
3830 return TRUE; /* DOS names are <= 8 chars */
3832 lpszPath++;
3834 return FALSE; /* Valid DOS path */
3837 /*************************************************************************
3838 * PathIsDirectoryEmptyA [SHLWAPI.@]
3840 * Determine if a given directory is empty.
3842 * PARAMS
3843 * lpszPath [I] Directory to check
3845 * RETURNS
3846 * TRUE If the directory exists and contains no files,
3847 * FALSE Otherwise
3849 BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
3851 BOOL bRet = FALSE;
3853 TRACE("(%s)\n",debugstr_a(lpszPath));
3855 if (lpszPath)
3857 WCHAR szPath[MAX_PATH];
3858 MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
3859 bRet = PathIsDirectoryEmptyW(szPath);
3861 return bRet;
3864 /*************************************************************************
3865 * PathIsDirectoryEmptyW [SHLWAPI.@]
3867 * See PathIsDirectoryEmptyA.
3869 BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
3871 static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
3872 WCHAR szSearch[MAX_PATH];
3873 DWORD dwLen;
3874 HANDLE hfind;
3875 BOOL retVal = TRUE;
3876 WIN32_FIND_DATAW find_data;
3878 TRACE("(%s)\n",debugstr_w(lpszPath));
3880 if (!lpszPath || !PathIsDirectoryW(lpszPath))
3881 return FALSE;
3883 lstrcpynW(szSearch, lpszPath, MAX_PATH);
3884 PathAddBackslashW(szSearch);
3885 dwLen = strlenW(szSearch);
3886 if (dwLen > MAX_PATH - 4)
3887 return FALSE;
3889 strcpyW(szSearch + dwLen, szAllFiles);
3890 hfind = FindFirstFileW(szSearch, &find_data);
3891 if (hfind == INVALID_HANDLE_VALUE)
3892 return FALSE;
3896 if (find_data.cFileName[0] == '.')
3898 if (find_data.cFileName[1] == '\0') continue;
3899 if (find_data.cFileName[1] == '.' && find_data.cFileName[2] == '\0') continue;
3902 retVal = FALSE;
3903 break;
3905 while (FindNextFileW(hfind, &find_data));
3907 FindClose(hfind);
3908 return retVal;
3912 /*************************************************************************
3913 * PathFindSuffixArrayA [SHLWAPI.@]
3915 * Find a suffix string in an array of suffix strings
3917 * PARAMS
3918 * lpszSuffix [I] Suffix string to search for
3919 * lppszArray [I] Array of suffix strings to search
3920 * dwCount [I] Number of elements in lppszArray
3922 * RETURNS
3923 * Success: The index of the position of lpszSuffix in lppszArray
3924 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3926 * NOTES
3927 * The search is case sensitive.
3928 * The match is made against the end of the suffix string, so for example:
3929 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3931 LPCSTR WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
3933 size_t dwLen;
3934 int dwRet = 0;
3936 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
3938 if (lpszSuffix && lppszArray && dwCount > 0)
3940 dwLen = strlen(lpszSuffix);
3942 while (dwRet < dwCount)
3944 size_t dwCompareLen = strlen(*lppszArray);
3945 if (dwCompareLen < dwLen)
3947 if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3948 return *lppszArray; /* Found */
3950 dwRet++;
3951 lppszArray++;
3954 return NULL;
3957 /*************************************************************************
3958 * PathFindSuffixArrayW [SHLWAPI.@]
3960 * See PathFindSuffixArrayA.
3962 LPCWSTR WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
3964 size_t dwLen;
3965 int dwRet = 0;
3967 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
3969 if (lpszSuffix && lppszArray && dwCount > 0)
3971 dwLen = strlenW(lpszSuffix);
3973 while (dwRet < dwCount)
3975 size_t dwCompareLen = strlenW(*lppszArray);
3976 if (dwCompareLen < dwLen)
3978 if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3979 return *lppszArray; /* Found */
3981 dwRet++;
3982 lppszArray++;
3985 return NULL;
3988 /*************************************************************************
3989 * PathUndecorateA [SHLWAPI.@]
3991 * Undecorate a file path
3993 * PARAMS
3994 * lpszPath [I/O] Path to remove any decoration from
3996 * RETURNS
3997 * Nothing
3999 * NOTES
4000 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
4002 VOID WINAPI PathUndecorateA(LPSTR lpszPath)
4004 TRACE("(%s)\n",debugstr_a(lpszPath));
4006 if (lpszPath)
4008 LPSTR lpszExt = PathFindExtensionA(lpszPath);
4009 if (lpszExt > lpszPath && lpszExt[-1] == ']')
4011 LPSTR lpszSkip = lpszExt - 2;
4012 if (*lpszSkip == '[')
4013 lpszSkip++; /* [] (no number) */
4014 else
4015 while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
4016 lpszSkip--;
4017 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
4019 /* remove the [n] */
4020 lpszSkip--;
4021 while (*lpszExt)
4022 *lpszSkip++ = *lpszExt++;
4023 *lpszSkip = '\0';
4029 /*************************************************************************
4030 * PathUndecorateW [SHLWAPI.@]
4032 * See PathUndecorateA.
4034 VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
4036 TRACE("(%s)\n",debugstr_w(lpszPath));
4038 if (lpszPath)
4040 LPWSTR lpszExt = PathFindExtensionW(lpszPath);
4041 if (lpszExt > lpszPath && lpszExt[-1] == ']')
4043 LPWSTR lpszSkip = lpszExt - 2;
4044 if (*lpszSkip == '[')
4045 lpszSkip++; /* [] (no number) */
4046 else
4047 while (lpszSkip > lpszPath && isdigitW(lpszSkip[-1]))
4048 lpszSkip--;
4049 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
4051 /* remove the [n] */
4052 lpszSkip--;
4053 while (*lpszExt)
4054 *lpszSkip++ = *lpszExt++;
4055 *lpszSkip = '\0';
4061 /*************************************************************************
4062 * PathUnExpandEnvStringsA [SHLWAPI.@]
4064 * Substitute folder names in a path with their corresponding environment
4065 * strings.
4067 * PARAMS
4068 * path [I] Buffer containing the path to unexpand.
4069 * buffer [O] Buffer to receive the unexpanded path.
4070 * buf_len [I] Size of pszBuf in characters.
4072 * RETURNS
4073 * Success: TRUE
4074 * Failure: FALSE
4076 BOOL WINAPI PathUnExpandEnvStringsA(LPCSTR path, LPSTR buffer, UINT buf_len)
4078 WCHAR bufferW[MAX_PATH], *pathW;
4079 DWORD len;
4080 BOOL ret;
4082 TRACE("(%s, %p, %d)\n", debugstr_a(path), buffer, buf_len);
4084 pathW = heap_strdupAtoW(path);
4085 if (!pathW) return FALSE;
4087 ret = PathUnExpandEnvStringsW(pathW, bufferW, MAX_PATH);
4088 HeapFree(GetProcessHeap(), 0, pathW);
4089 if (!ret) return FALSE;
4091 len = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL);
4092 if (buf_len < len + 1) return FALSE;
4094 WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, buf_len, NULL, NULL);
4095 return TRUE;
4098 static const WCHAR allusersprofileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4099 static const WCHAR appdataW[] = {'%','A','P','P','D','A','T','A','%',0};
4100 static const WCHAR computernameW[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4101 static const WCHAR programfilesW[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4102 static const WCHAR systemrootW[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4103 static const WCHAR systemdriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4104 static const WCHAR userprofileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4106 struct envvars_map
4108 const WCHAR *var;
4109 UINT varlen;
4110 WCHAR path[MAX_PATH];
4111 DWORD len;
4114 static void init_envvars_map(struct envvars_map *map)
4116 while (map->var)
4118 map->len = ExpandEnvironmentStringsW(map->var, map->path, sizeof(map->path)/sizeof(WCHAR));
4119 /* exclude null from length */
4120 if (map->len) map->len--;
4121 map++;
4125 /*************************************************************************
4126 * PathUnExpandEnvStringsW [SHLWAPI.@]
4128 * Unicode version of PathUnExpandEnvStringsA.
4130 BOOL WINAPI PathUnExpandEnvStringsW(LPCWSTR path, LPWSTR buffer, UINT buf_len)
4132 static struct envvars_map null_var = {NULL, 0, {0}, 0};
4133 struct envvars_map *match = &null_var, *cur;
4134 struct envvars_map envvars[] = {
4135 { allusersprofileW, sizeof(allusersprofileW)/sizeof(WCHAR) },
4136 { appdataW, sizeof(appdataW)/sizeof(WCHAR) },
4137 { computernameW, sizeof(computernameW)/sizeof(WCHAR) },
4138 { programfilesW, sizeof(programfilesW)/sizeof(WCHAR) },
4139 { systemrootW, sizeof(systemrootW)/sizeof(WCHAR) },
4140 { systemdriveW, sizeof(systemdriveW)/sizeof(WCHAR) },
4141 { userprofileW, sizeof(userprofileW)/sizeof(WCHAR) },
4142 { NULL }
4144 DWORD pathlen;
4145 UINT needed;
4147 TRACE("(%s, %p, %d)\n", debugstr_w(path), buffer, buf_len);
4149 pathlen = strlenW(path);
4150 init_envvars_map(envvars);
4151 cur = envvars;
4152 while (cur->var)
4154 /* path can't contain expanded value or value wasn't retrieved */
4155 if (cur->len == 0 || cur->len > pathlen || strncmpiW(cur->path, path, cur->len))
4157 cur++;
4158 continue;
4161 if (cur->len > match->len)
4162 match = cur;
4163 cur++;
4166 /* 'varlen' includes NULL termination char */
4167 needed = match->varlen + pathlen - match->len;
4168 if (match->len == 0 || needed > buf_len) return FALSE;
4170 strcpyW(buffer, match->var);
4171 strcatW(buffer, &path[match->len]);
4172 TRACE("ret %s\n", debugstr_w(buffer));
4174 return TRUE;
4177 /*************************************************************************
4178 * @ [SHLWAPI.440]
4180 * Find localised or default web content in "%WINDOWS%\web\".
4182 * PARAMS
4183 * lpszFile [I] File name containing content to look for
4184 * lpszPath [O] Buffer to contain the full path to the file
4185 * dwPathLen [I] Length of lpszPath
4187 * RETURNS
4188 * Success: S_OK. lpszPath contains the full path to the content.
4189 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4191 HRESULT WINAPI SHGetWebFolderFilePathA(LPCSTR lpszFile, LPSTR lpszPath, DWORD dwPathLen)
4193 WCHAR szFile[MAX_PATH], szPath[MAX_PATH];
4194 HRESULT hRet;
4196 TRACE("(%s,%p,%d)\n", lpszFile, lpszPath, dwPathLen);
4198 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, szFile, MAX_PATH);
4199 szPath[0] = '\0';
4200 hRet = SHGetWebFolderFilePathW(szFile, szPath, dwPathLen);
4201 WideCharToMultiByte(CP_ACP, 0, szPath, -1, lpszPath, dwPathLen, 0, 0);
4202 return hRet;
4205 /*************************************************************************
4206 * @ [SHLWAPI.441]
4208 * Unicode version of SHGetWebFolderFilePathA.
4210 HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR lpszFile, LPWSTR lpszPath, DWORD dwPathLen)
4212 static const WCHAR szWeb[] = {'\\','W','e','b','\\','\0'};
4213 static const WCHAR szWebMui[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4214 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4215 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4216 DWORD dwLen, dwFileLen;
4217 LANGID lidSystem, lidUser;
4219 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile), lpszPath, dwPathLen);
4221 /* Get base directory for web content */
4222 dwLen = GetSystemWindowsDirectoryW(lpszPath, dwPathLen);
4223 if (dwLen > 0 && lpszPath[dwLen-1] == '\\')
4224 dwLen--;
4226 dwFileLen = strlenW(lpszFile);
4228 if (dwLen + dwFileLen + szWebLen >= dwPathLen)
4229 return E_FAIL; /* lpszPath too short */
4231 strcpyW(lpszPath+dwLen, szWeb);
4232 dwLen += szWebLen;
4233 dwPathLen = dwPathLen - dwLen; /* Remaining space */
4235 lidSystem = GetSystemDefaultUILanguage();
4236 lidUser = GetUserDefaultUILanguage();
4238 if (lidSystem != lidUser)
4240 if (dwFileLen + szWebMuiLen < dwPathLen)
4242 /* Use localised content in the users UI language if present */
4243 wsprintfW(lpszPath + dwLen, szWebMui, lidUser);
4244 strcpyW(lpszPath + dwLen + szWebMuiLen, lpszFile);
4245 if (PathFileExistsW(lpszPath))
4246 return S_OK;
4250 /* Fall back to OS default installed content */
4251 strcpyW(lpszPath + dwLen, lpszFile);
4252 if (PathFileExistsW(lpszPath))
4253 return S_OK;
4254 return E_FAIL;
4257 #define PATH_CHAR_CLASS_LETTER 0x00000001
4258 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4259 #define PATH_CHAR_CLASS_DOT 0x00000004
4260 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4261 #define PATH_CHAR_CLASS_COLON 0x00000010
4262 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4263 #define PATH_CHAR_CLASS_COMMA 0x00000040
4264 #define PATH_CHAR_CLASS_SPACE 0x00000080
4265 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4266 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4268 #define PATH_CHAR_CLASS_INVALID 0x00000000
4269 #define PATH_CHAR_CLASS_ANY 0xffffffff
4271 static const DWORD SHELL_charclass[] =
4273 /* 0x00 */ PATH_CHAR_CLASS_INVALID, /* 0x01 */ PATH_CHAR_CLASS_INVALID,
4274 /* 0x02 */ PATH_CHAR_CLASS_INVALID, /* 0x03 */ PATH_CHAR_CLASS_INVALID,
4275 /* 0x04 */ PATH_CHAR_CLASS_INVALID, /* 0x05 */ PATH_CHAR_CLASS_INVALID,
4276 /* 0x06 */ PATH_CHAR_CLASS_INVALID, /* 0x07 */ PATH_CHAR_CLASS_INVALID,
4277 /* 0x08 */ PATH_CHAR_CLASS_INVALID, /* 0x09 */ PATH_CHAR_CLASS_INVALID,
4278 /* 0x0a */ PATH_CHAR_CLASS_INVALID, /* 0x0b */ PATH_CHAR_CLASS_INVALID,
4279 /* 0x0c */ PATH_CHAR_CLASS_INVALID, /* 0x0d */ PATH_CHAR_CLASS_INVALID,
4280 /* 0x0e */ PATH_CHAR_CLASS_INVALID, /* 0x0f */ PATH_CHAR_CLASS_INVALID,
4281 /* 0x10 */ PATH_CHAR_CLASS_INVALID, /* 0x11 */ PATH_CHAR_CLASS_INVALID,
4282 /* 0x12 */ PATH_CHAR_CLASS_INVALID, /* 0x13 */ PATH_CHAR_CLASS_INVALID,
4283 /* 0x14 */ PATH_CHAR_CLASS_INVALID, /* 0x15 */ PATH_CHAR_CLASS_INVALID,
4284 /* 0x16 */ PATH_CHAR_CLASS_INVALID, /* 0x17 */ PATH_CHAR_CLASS_INVALID,
4285 /* 0x18 */ PATH_CHAR_CLASS_INVALID, /* 0x19 */ PATH_CHAR_CLASS_INVALID,
4286 /* 0x1a */ PATH_CHAR_CLASS_INVALID, /* 0x1b */ PATH_CHAR_CLASS_INVALID,
4287 /* 0x1c */ PATH_CHAR_CLASS_INVALID, /* 0x1d */ PATH_CHAR_CLASS_INVALID,
4288 /* 0x1e */ PATH_CHAR_CLASS_INVALID, /* 0x1f */ PATH_CHAR_CLASS_INVALID,
4289 /* ' ' */ PATH_CHAR_CLASS_SPACE, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID,
4290 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID,
4291 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID,
4292 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID,
4293 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID,
4294 /* '*' */ PATH_CHAR_CLASS_ASTERIX, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID,
4295 /* ',' */ PATH_CHAR_CLASS_COMMA, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID,
4296 /* '.' */ PATH_CHAR_CLASS_DOT, /* '/' */ PATH_CHAR_CLASS_INVALID,
4297 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID,
4298 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID,
4299 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID,
4300 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID,
4301 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID,
4302 /* ':' */ PATH_CHAR_CLASS_COLON, /* ';' */ PATH_CHAR_CLASS_SEMICOLON,
4303 /* '<' */ PATH_CHAR_CLASS_INVALID, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID,
4304 /* '>' */ PATH_CHAR_CLASS_INVALID, /* '?' */ PATH_CHAR_CLASS_LETTER,
4305 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID, /* 'A' */ PATH_CHAR_CLASS_ANY,
4306 /* 'B' */ PATH_CHAR_CLASS_ANY, /* 'C' */ PATH_CHAR_CLASS_ANY,
4307 /* 'D' */ PATH_CHAR_CLASS_ANY, /* 'E' */ PATH_CHAR_CLASS_ANY,
4308 /* 'F' */ PATH_CHAR_CLASS_ANY, /* 'G' */ PATH_CHAR_CLASS_ANY,
4309 /* 'H' */ PATH_CHAR_CLASS_ANY, /* 'I' */ PATH_CHAR_CLASS_ANY,
4310 /* 'J' */ PATH_CHAR_CLASS_ANY, /* 'K' */ PATH_CHAR_CLASS_ANY,
4311 /* 'L' */ PATH_CHAR_CLASS_ANY, /* 'M' */ PATH_CHAR_CLASS_ANY,
4312 /* 'N' */ PATH_CHAR_CLASS_ANY, /* 'O' */ PATH_CHAR_CLASS_ANY,
4313 /* 'P' */ PATH_CHAR_CLASS_ANY, /* 'Q' */ PATH_CHAR_CLASS_ANY,
4314 /* 'R' */ PATH_CHAR_CLASS_ANY, /* 'S' */ PATH_CHAR_CLASS_ANY,
4315 /* 'T' */ PATH_CHAR_CLASS_ANY, /* 'U' */ PATH_CHAR_CLASS_ANY,
4316 /* 'V' */ PATH_CHAR_CLASS_ANY, /* 'W' */ PATH_CHAR_CLASS_ANY,
4317 /* 'X' */ PATH_CHAR_CLASS_ANY, /* 'Y' */ PATH_CHAR_CLASS_ANY,
4318 /* 'Z' */ PATH_CHAR_CLASS_ANY, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID,
4319 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID,
4320 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID,
4321 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID, /* 'a' */ PATH_CHAR_CLASS_ANY,
4322 /* 'b' */ PATH_CHAR_CLASS_ANY, /* 'c' */ PATH_CHAR_CLASS_ANY,
4323 /* 'd' */ PATH_CHAR_CLASS_ANY, /* 'e' */ PATH_CHAR_CLASS_ANY,
4324 /* 'f' */ PATH_CHAR_CLASS_ANY, /* 'g' */ PATH_CHAR_CLASS_ANY,
4325 /* 'h' */ PATH_CHAR_CLASS_ANY, /* 'i' */ PATH_CHAR_CLASS_ANY,
4326 /* 'j' */ PATH_CHAR_CLASS_ANY, /* 'k' */ PATH_CHAR_CLASS_ANY,
4327 /* 'l' */ PATH_CHAR_CLASS_ANY, /* 'm' */ PATH_CHAR_CLASS_ANY,
4328 /* 'n' */ PATH_CHAR_CLASS_ANY, /* 'o' */ PATH_CHAR_CLASS_ANY,
4329 /* 'p' */ PATH_CHAR_CLASS_ANY, /* 'q' */ PATH_CHAR_CLASS_ANY,
4330 /* 'r' */ PATH_CHAR_CLASS_ANY, /* 's' */ PATH_CHAR_CLASS_ANY,
4331 /* 't' */ PATH_CHAR_CLASS_ANY, /* 'u' */ PATH_CHAR_CLASS_ANY,
4332 /* 'v' */ PATH_CHAR_CLASS_ANY, /* 'w' */ PATH_CHAR_CLASS_ANY,
4333 /* 'x' */ PATH_CHAR_CLASS_ANY, /* 'y' */ PATH_CHAR_CLASS_ANY,
4334 /* 'z' */ PATH_CHAR_CLASS_ANY, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID,
4335 /* '|' */ PATH_CHAR_CLASS_INVALID, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID,
4336 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4339 /*************************************************************************
4340 * @ [SHLWAPI.455]
4342 * Check if an ASCII char is of a certain class
4344 BOOL WINAPI PathIsValidCharA( char c, DWORD class )
4346 if ((unsigned)c > 0x7e)
4347 return class & PATH_CHAR_CLASS_OTHER_VALID;
4349 return class & SHELL_charclass[(unsigned)c];
4352 /*************************************************************************
4353 * @ [SHLWAPI.456]
4355 * Check if a Unicode char is of a certain class
4357 BOOL WINAPI PathIsValidCharW( WCHAR c, DWORD class )
4359 if (c > 0x7e)
4360 return class & PATH_CHAR_CLASS_OTHER_VALID;
4362 return class & SHELL_charclass[c];