From 7b65e175393f6b636d6c53beed4ef693c018a1d6 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 4 Jan 2005 13:24:56 +0000 Subject: [PATCH] Test for OS support for symbolic links and protect support library code appropriately. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9421 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 10 ++++++++++ src/support/FileInfo.C | 21 ++++++++++++++++++--- src/support/filetools.C | 4 ++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index f1ea1ebe3c..61b0b146da 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,13 @@ +2005-01-04 Angus Leeming + + * FileInfo.C (FileInfo, newFile): strip the trailing '/' from + the stored file name as it breaks Window's version of stat(). + (isLink): protect the code with #ifdef S_ISLNK. + (dostat): protect the code with #ifdef HAVE_LSTAT. + + * filetools.C (LyXReadLink): protect the code with + #ifdef HAVE_READLINK. + 2005-01-01 Kayvan Sylvan * os_win32.C (internal_path): remove the call to MakeLatexName as diff --git a/src/support/FileInfo.C b/src/support/FileInfo.C index 99825685f0..342e5e92d4 100644 --- a/src/support/FileInfo.C +++ b/src/support/FileInfo.C @@ -11,10 +11,13 @@ #include #include "support/FileInfo.h" +#include "support/lstrings.h" #include #include +#include +#include using std::string; @@ -141,7 +144,6 @@ char typeLetter(mode_t i) return '?'; } - } // namespace anon @@ -155,7 +157,9 @@ FileInfo::FileInfo() FileInfo::FileInfo(string const & path, bool link) - : fname_(path) + // Win32 stat() doesn't dig trailing slashes. + // Posix stat() doesn't care, but we'll remove it anyway. + : fname_(rtrim(path, "/")) { init(); dostat(link); @@ -180,10 +184,15 @@ void FileInfo::init() void FileInfo::dostat(bool link) { +#ifdef HAVE_LSTAT if (link) status_ = ::lstat(fname_.c_str(), &buf_); else status_ = ::stat(fname_.c_str(), &buf_); +#else + status_ = ::stat(fname_.c_str(), &buf_); +#endif + if (status_) err_ = errno; } @@ -191,7 +200,9 @@ void FileInfo::dostat(bool link) FileInfo & FileInfo::newFile(string const & path, bool link) { - fname_ = path; + // Win32 stat() doesn't dig trailing slashes. + // Posix stat() doesn't care, but we'll remove it anyway. + fname_ = rtrim(path, "/"); status_ = 0; err_ = NoErr; dostat(link); @@ -314,7 +325,11 @@ bool FileInfo::isOK() const bool FileInfo::isLink() const { BOOST_ASSERT(isOK()); +#ifdef S_ISLNK return S_ISLNK(buf_.st_mode); +#else + return false; +#endif } diff --git a/src/support/filetools.C b/src/support/filetools.C index 481b8ec886..7f3a6c5e96 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1145,6 +1145,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold) bool LyXReadLink(string const & file, string & link, bool resolve) { +#ifdef HAVE_READLINK char linkbuffer[512]; // Should be PATH_MAX but that needs autconf support int const nRead = ::readlink(file.c_str(), @@ -1157,6 +1158,9 @@ bool LyXReadLink(string const & file, string & link, bool resolve) else link = linkbuffer; return true; +#else + return false; +#endif } -- 2.39.5