-
Sam Yates authored
Two MacPorts/gcc7 issues: std::uint64_t is unsigned long long on OS X, breaking an assumption about size_t in the distributed_context interface. Problems with missing errno defines in the standard library headers. With MacPorts gcc7, the installed c++config.h defines _GLIBCXX_HAVE_EOWNERDEAD and _GLIBCXX_HAVE_ENOTRECOVERABLE, but the corresponding errno defines are not provided by sys/errno.h unless __DARWIN_C_SOURCE, which takes its value from _POSIX_C_SOURCE if defined, is greater than or equal to 200809L. Technically a MacPorts configuration bug? but easily worked around. Use basic integral types for communication collectives interfaces. Define _POSIX_C_SOURCE to be 200809L for glob.cpp. Fixes #562.
3bafa1b3
glob.cpp 973 B
// POSIX headers
extern "C" {
#define _POSIX_C_SOURCE 200809L
#include <glob.h>
}
// GLOB_TILDE and GLOB_BRACE are non-standard but convenient and common
// flags for glob().
#ifndef GLOB_TILDE
#define GLOB_TILDE 0
#endif
#ifndef GLOB_BRACE
#define GLOB_BRACE 0
#endif
#include <cerrno>
#include <aux/path.hpp>
#include <aux/scope_exit.hpp>
namespace aux {
std::vector<path> glob(const std::string& pattern) {
std::vector<path> paths;
glob_t matches;
int flags = GLOB_MARK | GLOB_NOCHECK | GLOB_TILDE | GLOB_BRACE;
auto r = ::glob(pattern.c_str(), flags, nullptr, &matches);
auto glob_guard = on_scope_exit([&]() { ::globfree(&matches); });
if (r==GLOB_NOSPACE) {
throw std::bad_alloc{};
}
else if (r==0) {
// success
paths.reserve(matches.gl_pathc);
for (auto pathp = matches.gl_pathv; *pathp; ++pathp) {
paths.push_back(*pathp);
}
}
return paths;
}
} // namespace aux