Backport r39333 to fix bug #7467: PATH_MAX related build failure on GNU/Hurd.

(Patch from Pino, adapted for trunk by Sven)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39342 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John C. McCabe-Dansted 2011-07-19 04:14:09 +00:00
parent 6467f4657a
commit 6a60ef8ab4
2 changed files with 22 additions and 1 deletions

View File

@ -49,6 +49,7 @@
#include <utility>
#include <fstream>
#include <sstream>
#include <vector>
#if defined (_WIN32)
#include <io.h>
@ -795,13 +796,31 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
#ifdef HAVE_READLINK
bool readLink(FileName const & file, FileName & link)
{
char linkbuffer[PATH_MAX + 1];
string const encoded = file.toFilesystemEncoding();
#ifdef HAVE_DEF_PATH_MAX
char linkbuffer[PATH_MAX + 1];
int const nRead = ::readlink(encoded.c_str(),
linkbuffer, sizeof(linkbuffer) - 1);
if (nRead <= 0)
return false;
linkbuffer[nRead] = '\0'; // terminator
#else
vector<char> buf(1024);
int nRead = -1;
while (true) {
nRead = ::readlink(encoded.c_str(), &buf[0], buf.size() - 1);
if (nRead < 0) {
return false;
}
if (nRead < buf.size() - 1) {
break;
}
buf.resize(buf.size() * 2);
}
buf[nRead] = '\0'; // terminator
const char * linkbuffer = &buf[0];
#endif
link = makeAbsPath(linkbuffer, onlyPath(file.absFileName()));
return true;
}

View File

@ -273,3 +273,5 @@ What's new
- Using pkgconfig to configure hunspell (hunspell 1.3 was not correctly
recognized).
- Fixed build failure on GNU/Hurd, which doesn't define PATH_MAX (bug #7467).