From: John C. McCabe-Dansted Date: Sun, 17 Jul 2011 12:32:00 +0000 (+0000) Subject: Fix bug #7467: build failure on GNU/Hurd, which doesn't define PATH_MAX. X-Git-Tag: 2.1.0beta1~2904 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2885ea392159ae272d3fbedbdeda201a3d0f243a;p=features.git Fix bug #7467: build failure on GNU/Hurd, which doesn't define PATH_MAX. (Patch from Pino, adapted for trunk by Sven) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39333 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index dbf91ee59e..dc4e3cd5bd 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #if defined (_WIN32) #include @@ -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 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; }