From 783a311643a42dc0102b95cf58f8886f1822c809 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 4 Jan 2005 13:24:55 +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/branches/BRANCH_1_3_X@9420 a592a061-630c-0410-9148-cb99ea01b6c8 --- config/ChangeLog | 5 +++++ config/configure.ac | 4 +++- config/configure.in | 3 ++- src/support/ChangeLog | 10 ++++++++++ src/support/FileInfo.C | 28 +++++++++++++++++++++------- src/support/filetools.C | 4 ++++ 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/config/ChangeLog b/config/ChangeLog index 83426da17b..20df4fe7af 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,8 @@ +2005-01-04 Angus Leeming + + * configure.ac, configure.in (AC_CHECK_FUNCS): test for the + existence of lstat and readlink. + 2004-12-16 Angus Leeming * configure.ac: remove the HAVE_MKDIR conditional code to diff --git a/config/configure.ac b/config/configure.ac index 3986adf9f7..97c551b697 100644 --- a/config/configure.ac +++ b/config/configure.ac @@ -256,9 +256,11 @@ dnl work correctly because of some conflict with stdlib.h with g++ 2.96 dnl We aim to remove this eventually, since we should test as much as dnl possible with the compiler which will use the functions (JMarc) AC_LANG_PUSH(C) -AC_CHECK_FUNCS(memmove memset strchr putenv setenv mkfifo mkstemp mktemp) +AC_CHECK_FUNCS(memmove memset strchr putenv setenv mkfifo mkstemp mktemp \ + lstat readlink) AC_LANG_POP(C) + dnl Until this is fixed in autoconf we provide our own version AC_FUNC_SELECT_ARGTYPES diff --git a/config/configure.in b/config/configure.in index 13bc8c14d6..5a3c9e9f7e 100644 --- a/config/configure.in +++ b/config/configure.in @@ -259,7 +259,8 @@ dnl work correctly because of some conflict with stdlib.h with g++ 2.96 dnl We aim to remove this eventually, since we should test as much as dnl possible with the compiler which will use the functions (JMarc) AC_LANG_C -AC_CHECK_FUNCS(memmove memset strchr putenv setenv mkfifo mkstemp mktemp) +AC_CHECK_FUNCS(memmove memset strchr putenv setenv mkfifo mkstemp mktemp \ + lstat readlink) AC_LANG_CPLUSPLUS dnl Until this is fixed in autoconf we provide our own version diff --git a/src/support/ChangeLog b/src/support/ChangeLog index a82a04f022..25df176654 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 f21fc132f8..ef2b06b691 100644 --- a/src/support/FileInfo.C +++ b/src/support/FileInfo.C @@ -10,12 +10,14 @@ #include -//#include -//#include - -#include #include "FileInfo.h" #include "LAssert.h" +#include "lstrings.h" + +#include +#include + +#include #if !S_IRUSR # if S_IREAD @@ -138,7 +140,6 @@ char typeLetter(mode_t i) return '?'; } - } // namespace anon @@ -149,7 +150,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); @@ -174,10 +177,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; } @@ -185,7 +193,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); @@ -308,7 +318,11 @@ bool FileInfo::isOK() const bool FileInfo::isLink() const { lyx::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 bc98d155e5..3ce53027e0 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1247,6 +1247,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(), @@ -1259,6 +1260,9 @@ bool LyXReadLink(string const & file, string & link, bool resolve) else link = linkbuffer; return true; +#else + return false; +#endif }