]> git.lyx.org Git - features.git/commitdiff
Fix bug #7467: build failure on GNU/Hurd, which doesn't define PATH_MAX.
authorJohn C. McCabe-Dansted <cmd@lyx.org>
Sun, 17 Jul 2011 12:32:00 +0000 (12:32 +0000)
committerJohn C. McCabe-Dansted <cmd@lyx.org>
Sun, 17 Jul 2011 12:32:00 +0000 (12:32 +0000)
(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

src/support/filetools.cpp

index dbf91ee59e10c7fd89e45e1a6f40b13b2727b776..dc4e3cd5bd922fc48142ed4f537265e4536c4136 100644 (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;
 }