From 0c0b09ec526f39eddf41e69cf8f24ae53c91a25d Mon Sep 17 00:00:00 2001 From: Victor Hora Date: Thu, 26 Jul 2018 16:19:51 -0400 Subject: [PATCH] Use glob.h when using OpenBSD --- src/utils/string.cc | 4 ++++ src/utils/system.cc | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/utils/string.cc b/src/utils/string.cc index 4732eec4..37c20a0d 100644 --- a/src/utils/string.cc +++ b/src/utils/string.cc @@ -17,7 +17,11 @@ #include #include #include +#ifdef __OpenBSD__ +#include +#else #include +#endif #include #include diff --git a/src/utils/system.cc b/src/utils/system.cc index d832640e..730999e9 100644 --- a/src/utils/system.cc +++ b/src/utils/system.cc @@ -17,7 +17,11 @@ #include #include #include +#ifdef __OpenBSD__ +#include +#else #include +#endif #include #include @@ -119,10 +123,17 @@ std::string get_path(const std::string& file) { std::list expandEnv(const std::string& var, int flags) { std::list vars; +#ifdef __OpenBSD__ + glob_t p; + if (glob(var.c_str(), flags, NULL, &p) == false) { + if (p.gl_pathc) { + for (char** exp = p.gl_pathv; *exp; ++exp) { +#else wordexp_t p; if (wordexp(var.c_str(), &p, flags) == false) { if (p.we_wordc) { for (char** exp = p.we_wordv; *exp; ++exp) { +#endif std::ifstream *iss = new std::ifstream(exp[0], std::ios::in); if (iss->is_open()) { iss->close(); @@ -131,12 +142,15 @@ std::list expandEnv(const std::string& var, int flags) { delete iss; } } +#ifdef __OpenBSD__ + globfree(&p); +#else wordfree(&p); +#endif } return vars; } - bool createDir(std::string dir, int mode, std::string *error) { int ret = mkdir(dir.data(), mode); if (ret != 0 && errno != EEXIST) {