diff --git a/src/file.cc b/src/file.cc index 653b2083..68c24bdd 100644 --- a/src/file.cc +++ b/src/file.cc @@ -275,15 +275,12 @@ std::vector list_files(const String& prefix, { kak_assert(dirname.empty() or dirname.back() == '/'); DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str()); - auto closeDir = on_scope_end([=]{ - if (dir != NULL) - closedir(dir); - }); + if (not dir) + return {}; + + auto closeDir = on_scope_end([=]{ closedir(dir); }); std::vector result; - if (not dir) - return result; - std::vector subseq_result; while (dirent* entry = readdir(dir)) { @@ -309,8 +306,7 @@ std::vector list_files(const String& prefix, } } } - auto& real_result = result.empty() ? subseq_result : result; - return real_result; + return result.empty() ? subseq_result : result; } std::vector complete_filename(const String& prefix,