prevent crash on some glob.h versions

This commit is contained in:
David Rose 2004-06-06 01:28:57 +00:00
parent 33f587a56d
commit 08ea68e8ab

View File

@ -1210,12 +1210,23 @@ scan_directory(vector_string &contents) const {
glob_t globbuf; glob_t globbuf;
int r = glob(dirname.c_str(), GLOB_ERR, NULL, &globbuf); int r = glob(dirname.c_str(), GLOB_ERR, NULL, &globbuf);
if (r != 0) {
// Some error processing the match string. If our version of
// glob.h defines GLOB_NOMATCH, then we can differentiate an empty
// return result from some other kind of error.
#ifdef GLOB_NOMATCH #ifdef GLOB_NOMATCH
if (r != 0 && r != GLOB_NOMATCH) { if (r != GLOB_NOMATCH) {
perror(dirname.c_str()); perror(dirname.c_str());
return false; return false;
} }
#endif #endif
// Otherwise, all errors mean the same thing: no matches, but
// otherwise no problem.
return true;
}
size_t offset = dirname.size() - 1; size_t offset = dirname.size() - 1;
for (int i = 0; globbuf.gl_pathv[i] != NULL; i++) { for (int i = 0; globbuf.gl_pathv[i] != NULL; i++) {