aboutsummaryrefslogtreecommitdiff
path: root/c/ext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/ext.cpp')
-rw-r--r--c/ext.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/c/ext.cpp b/c/ext.cpp
index f485dce..ee2c943 100644
--- a/c/ext.cpp
+++ b/c/ext.cpp
@@ -76,6 +76,8 @@ static inline bool MatchFileName(wchar_t (&file)[MAX_PATH], const wchar_t* const
static bool FindMatchingFile(wchar_t (&file)[MAX_PATH], const wchar_t* const root,
const wchar_t* const siEp, const int level = 0)
{
+ using FindHandle = Managed<HANDLE, FindClose, Win32Error, -1>;
+
/* Don't recurse too much. */
if (level > 3)
return false;
@@ -84,9 +86,7 @@ static bool FindMatchingFile(wchar_t (&file)[MAX_PATH], const wchar_t* const roo
Swprintf(pat, L"%s\\*", root);
WIN32_FIND_DATA fdata;
- HANDLE hf = FindFirstFile(pat, &fdata);
- if (hf == INVALID_HANDLE_VALUE)
- throw Win32Error().what();
+ FindHandle h = FindFirstFile(pat, &fdata);
do {
if (fdata.cFileName[0] == L'.')
@@ -95,25 +95,18 @@ static bool FindMatchingFile(wchar_t (&file)[MAX_PATH], const wchar_t* const roo
/* Recurse into directory. */
wchar_t root2[MAX_PATH];
Swprintf(root2, L"%s\\%s", root, fdata.cFileName);
- try {
- if (FindMatchingFile(file, root2, siEp, level+1))
- return true;
- } catch (...) {
- FindClose(hf);
- throw;
- }
+ if (FindMatchingFile(file, root2, siEp, level+1))
+ return true;
}
else /* Try to match file name. */
if (MatchFileName(fdata.cFileName, siEp)) {
Swprintf(file, L"%s\\%s", root, fdata.cFileName);
return true;
}
- } while (FindNextFile(hf, &fdata));
+ } while (FindNextFile(h, &fdata));
- DWORD e = GetLastError();
- FindClose(hf);
- if (e != ERROR_NO_MORE_FILES)
- throw Win32Error(e);
+ if (GetLastError() != ERROR_NO_MORE_FILES)
+ throw Win32Error();
return false;
}