Use glob.h when using OpenBSD

This commit is contained in:
Victor Hora 2018-07-26 16:19:51 -04:00 committed by Felipe Zimmerle
parent d97688804e
commit 0c0b09ec52
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 19 additions and 1 deletions

View File

@ -17,7 +17,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#ifdef __OpenBSD__
#include <glob.h>
#else
#include <wordexp.h> #include <wordexp.h>
#endif
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>

View File

@ -17,7 +17,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#ifdef __OpenBSD__
#include <glob.h>
#else
#include <wordexp.h> #include <wordexp.h>
#endif
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
@ -119,10 +123,17 @@ std::string get_path(const std::string& file) {
std::list<std::string> expandEnv(const std::string& var, int flags) { std::list<std::string> expandEnv(const std::string& var, int flags) {
std::list<std::string> vars; std::list<std::string> 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; wordexp_t p;
if (wordexp(var.c_str(), &p, flags) == false) { if (wordexp(var.c_str(), &p, flags) == false) {
if (p.we_wordc) { if (p.we_wordc) {
for (char** exp = p.we_wordv; *exp; ++exp) { for (char** exp = p.we_wordv; *exp; ++exp) {
#endif
std::ifstream *iss = new std::ifstream(exp[0], std::ios::in); std::ifstream *iss = new std::ifstream(exp[0], std::ios::in);
if (iss->is_open()) { if (iss->is_open()) {
iss->close(); iss->close();
@ -131,12 +142,15 @@ std::list<std::string> expandEnv(const std::string& var, int flags) {
delete iss; delete iss;
} }
} }
#ifdef __OpenBSD__
globfree(&p);
#else
wordfree(&p); wordfree(&p);
#endif
} }
return vars; return vars;
} }
bool createDir(std::string dir, int mode, std::string *error) { bool createDir(std::string dir, int mode, std::string *error) {
int ret = mkdir(dir.data(), mode); int ret = mkdir(dir.data(), mode);
if (ret != 0 && errno != EEXIST) { if (ret != 0 && errno != EEXIST) {