+// Converts forward slashes to backslashes and removes duplicate slashes.
+// Necessary because some (buggy?) EFI implementations produce "\/" strings
+// in pathnames.
+static VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) {
+ CHAR16 *NewName;
+ UINTN i, j = 0;
+ BOOLEAN LastWasSlash = FALSE;
+
+ NewName = AllocateZeroPool(sizeof(CHAR16) * (StrLen(PathName) + 1));
+ if (NewName != NULL) {
+ for (i = 0; i < StrLen(PathName); i++) {
+ if ((PathName[i] == L'/') || (PathName[i] == L'\\')) {
+ if (!LastWasSlash)
+ NewName[j++] = L'\\';
+ LastWasSlash = TRUE;
+ } else {
+ NewName[j++] = PathName[i];
+ LastWasSlash = FALSE;
+ } // if/else
+ } // for
+ NewName[j] = 0;
+ // Copy the transformed name back....
+ StrCpy(PathName, NewName);
+ FreePool(NewName);
+ } // if allocation OK
+} // CleanUpPathNameSlashes()
+