Skip to content

Commit 0c0b09e

Browse files
victorhoraFelipe Zimmerle
authored andcommitted
Use glob.h when using OpenBSD
1 parent d976888 commit 0c0b09e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/utils/string.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#include <stdlib.h>
1818
#include <stddef.h>
1919
#include <string.h>
20+
#ifdef __OpenBSD__
21+
#include <glob.h>
22+
#else
2023
#include <wordexp.h>
24+
#endif
2125
#include <stdint.h>
2226
#include <inttypes.h>
2327

src/utils/system.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#include <stdlib.h>
1818
#include <stddef.h>
1919
#include <string.h>
20+
#ifdef __OpenBSD__
21+
#include <glob.h>
22+
#else
2023
#include <wordexp.h>
24+
#endif
2125
#include <stdint.h>
2226
#include <inttypes.h>
2327

@@ -119,10 +123,17 @@ std::string get_path(const std::string& file) {
119123
std::list<std::string> expandEnv(const std::string& var, int flags) {
120124
std::list<std::string> vars;
121125

126+
#ifdef __OpenBSD__
127+
glob_t p;
128+
if (glob(var.c_str(), flags, NULL, &p) == false) {
129+
if (p.gl_pathc) {
130+
for (char** exp = p.gl_pathv; *exp; ++exp) {
131+
#else
122132
wordexp_t p;
123133
if (wordexp(var.c_str(), &p, flags) == false) {
124134
if (p.we_wordc) {
125135
for (char** exp = p.we_wordv; *exp; ++exp) {
136+
#endif
126137
std::ifstream *iss = new std::ifstream(exp[0], std::ios::in);
127138
if (iss->is_open()) {
128139
iss->close();
@@ -131,12 +142,15 @@ std::list<std::string> expandEnv(const std::string& var, int flags) {
131142
delete iss;
132143
}
133144
}
145+
#ifdef __OpenBSD__
146+
globfree(&p);
147+
#else
134148
wordfree(&p);
149+
#endif
135150
}
136151
return vars;
137152
}
138153

139-
140154
bool createDir(std::string dir, int mode, std::string *error) {
141155
int ret = mkdir(dir.data(), mode);
142156
if (ret != 0 && errno != EEXIST) {

0 commit comments

Comments
 (0)