Fixed #3947 (build failure if PATH_MAX is not defined)

This commit is contained in:
Pino Toscano 2012-07-07 19:55:43 +02:00 committed by Daniel Marjamäki
parent 38be0db959
commit 5262ba16d9
1 changed files with 12 additions and 3 deletions

View File

@ -21,9 +21,11 @@
#include <fstream> #include <fstream>
#ifndef _WIN32 #ifndef _WIN32
#include <vector>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#endif #endif
class TestFileLister: public TestFixture { class TestFileLister: public TestFixture {
@ -55,11 +57,18 @@ private:
#ifndef _WIN32 #ifndef _WIN32
void absolutePath() { void absolutePath() {
char current_dir[PATH_MAX]; std::vector<char> current_dir;
getcwd(current_dir, sizeof(current_dir)); #ifdef PATH_MAX
current_dir.resize(PATH_MAX);
#else
current_dir.resize(1024);
#endif
while (getcwd(&current_dir[0], current_dir.size()) == NULL && errno == ERANGE) {
current_dir.resize(current_dir.size() + 1024);
}
std::string absolute_path = FileLister::getAbsolutePath("."); std::string absolute_path = FileLister::getAbsolutePath(".");
ASSERT_EQUALS(current_dir, absolute_path); ASSERT_EQUALS(&current_dir[0], absolute_path);
} }
#endif #endif