Skip to content

Commit 5cb237e

Browse files
committed
Replace glob with cross-platform std::filesystem version
1 parent bc08c60 commit 5cb237e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/terminal/ParseConfigFile.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// #include <string.h>
77
// #include <unistd.h>
88

9-
#include <glob.h>
9+
#include <filesystem>
1010

1111
#include <fstream>
1212
#include <iostream>
@@ -1250,14 +1250,17 @@ static int ssh_config_parse_line(const char *targethost,
12501250
if (p) {
12511251
char *filename = ssh_path_expand_tilde(p);
12521252
if (filename) {
1253-
glob_t g;
12541253
if (strchr(filename, '*') || strchr(filename, '?')) {
1255-
if (glob(filename, 0, NULL, &g) == 0) {
1256-
for (size_t i = 0; i < g.gl_pathc; ++i) {
1257-
local_parse_file(targethost, options, g.gl_pathv[i], parsing,
1258-
seen);
1254+
std::string dir = fs::path(filename).parent_path().string();
1255+
std::string pattern = fs::path(filename).filename().string();
1256+
std::regex pattern_regex(
1257+
std::regex_replace(std::regex_replace(pattern, std::regex(R"(\.)"), R"(\.)"),
1258+
std::regex(R"(\*)"), ".*")
1259+
);
1260+
for (const auto& entry : fs::directory_iterator(dir.empty() ? "." : dir)) {
1261+
if (std::regex_match(entry.path().filename().string(), pattern_regex)) {
1262+
local_parse_file(targethost, options, entry.path().string().c_str(), parsing, seen);
12591263
}
1260-
globfree(&g);
12611264
}
12621265
} else {
12631266
local_parse_file(targethost, options, filename, parsing, seen);

0 commit comments

Comments
 (0)