Skip to content

Commit

Permalink
Fixed file name comparisions by #include and FileInstall (non-compiled).
Browse files Browse the repository at this point in the history
Differences are as described for lstrcmpi (old) and CompareStringOrdinal
with bIgnoreCase = true (new):
https://learn.microsoft.com/en-us/windows/win32/intl/handling-sorting-in-your-applications#sort-strings-ordinally
  • Loading branch information
Lexikos committed Dec 23, 2023
1 parent 618cfb3 commit 31de908
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/lib/file.cpp
Expand Up @@ -531,7 +531,7 @@ static bool FileInstallCopy(LPCTSTR aSource, LPCTSTR aDest, bool aOverwrite)
SetCurrentDirectory(g_script.mFileDir);
GetFullPathName(aSource, _countof(source_path), source_path, NULL);
SetCurrentDirectory(g_WorkingDir); // Restore to proper value.
if (!lstrcmpi(source_path, dest_path) // Full paths are equal.
if (!ostrcmpi(source_path, dest_path) // Full paths are equal.
&& !(GetFileAttributes(source_path) & FILE_ATTRIBUTE_DIRECTORY)) // Source file exists and is not a directory (otherwise, an error should be thrown).
return true;

Expand Down
2 changes: 1 addition & 1 deletion source/script.cpp
Expand Up @@ -1559,7 +1559,7 @@ ResultType Script::OpenIncludedFile(TextStream *&ts, LPCTSTR aFileSpec, bool aAl
// to support automatic "include once" behavior. So just ignore repeats:
if (!aAllowDuplicateInclude)
for (int f = 0; f < source_file_index; ++f) // Here, source_file_index==Line::sSourceFileCount
if (!lstrcmpi(Line::sSourceFile[f], full_path)) // Case insensitive like the file system (testing shows that "Ä" == "ä" in the NTFS, which is hopefully how lstrcmpi works regardless of locale).
if (!ostrcmpi(Line::sSourceFile[f], full_path)) // Case insensitive like the file system (e.g. "Ä" == "ä" in the NTFS).
return OK;
// The path is copied into persistent memory further below, after the file has been opened,
// in case the opening fails and aIgnoreLoadFailure==true. Initialize for the check below.
Expand Down
4 changes: 4 additions & 0 deletions source/util.h
Expand Up @@ -595,6 +595,10 @@ int FTOA(double aValue, LPTSTR aBuf, int aBufSize);
// returns 0 on failure, but failure occurs only when parameter/flag is invalid, which should never happen in
// this case.
#define lstrcmpni(str1, len1, str2, len2) (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, str1, (int)(len1), str2, (int)(len2)) - 2) // -2 for maintainability
// Compare string using the operating system uppercasing table, independent of locale but treating non-ASCII
// letters such as è and È as equivalent. Documentation indicates it will be consistent with NTFS file names.
#define ostrcmpni(str1, len1, str2, len2) (CompareStringOrdinal(str1, (int)(len1), str2, (int)(len2), TRUE) - 2) // -2 for maintainability
#define ostrcmpi(str1, str2) (ostrcmpni(str1, -1, str2, -1))


// The following macros simplify and make consistent the calls to MultiByteToWideChar().
Expand Down

0 comments on commit 31de908

Please sign in to comment.