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
This commit is contained in:
Angus Leeming 2005-01-04 13:24:55 +00:00
parent 987df09ed3
commit 783a311643
6 changed files with 45 additions and 9 deletions

View File

@ -1,3 +1,8 @@
2005-01-04 Angus Leeming <leeming@lyx.org>
* configure.ac, configure.in (AC_CHECK_FUNCS): test for the
existence of lstat and readlink.
2004-12-16 Angus Leeming <leeming@lyx.org> 2004-12-16 Angus Leeming <leeming@lyx.org>
* configure.ac: remove the HAVE_MKDIR conditional code to * configure.ac: remove the HAVE_MKDIR conditional code to

View File

@ -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 We aim to remove this eventually, since we should test as much as
dnl possible with the compiler which will use the functions (JMarc) dnl possible with the compiler which will use the functions (JMarc)
AC_LANG_PUSH(C) 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) AC_LANG_POP(C)
dnl Until this is fixed in autoconf we provide our own version dnl Until this is fixed in autoconf we provide our own version
AC_FUNC_SELECT_ARGTYPES AC_FUNC_SELECT_ARGTYPES

View File

@ -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 We aim to remove this eventually, since we should test as much as
dnl possible with the compiler which will use the functions (JMarc) dnl possible with the compiler which will use the functions (JMarc)
AC_LANG_C 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 AC_LANG_CPLUSPLUS
dnl Until this is fixed in autoconf we provide our own version dnl Until this is fixed in autoconf we provide our own version

View File

@ -1,3 +1,13 @@
2005-01-04 Angus Leeming <leeming@lyx.org>
* 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 <kayvan@sylvan.com> 2005-01-01 Kayvan Sylvan <kayvan@sylvan.com>
* os_win32.C (internal_path): remove the call to MakeLatexName as * os_win32.C (internal_path): remove the call to MakeLatexName as

View File

@ -10,12 +10,14 @@
#include <config.h> #include <config.h>
//#include <sys/types.h>
//#include <sys/stat.h>
#include <cerrno>
#include "FileInfo.h" #include "FileInfo.h"
#include "LAssert.h" #include "LAssert.h"
#include "lstrings.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <cerrno>
#if !S_IRUSR #if !S_IRUSR
# if S_IREAD # if S_IREAD
@ -138,7 +140,6 @@ char typeLetter(mode_t i)
return '?'; return '?';
} }
} // namespace anon } // namespace anon
@ -149,7 +150,9 @@ FileInfo::FileInfo()
FileInfo::FileInfo(string const & path, bool link) 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(); init();
dostat(link); dostat(link);
@ -174,10 +177,15 @@ void FileInfo::init()
void FileInfo::dostat(bool link) void FileInfo::dostat(bool link)
{ {
#ifdef HAVE_LSTAT
if (link) if (link)
status_ = ::lstat(fname_.c_str(), &buf_); status_ = ::lstat(fname_.c_str(), &buf_);
else else
status_ = ::stat(fname_.c_str(), &buf_); status_ = ::stat(fname_.c_str(), &buf_);
#else
status_ = ::stat(fname_.c_str(), &buf_);
#endif
if (status_) if (status_)
err_ = errno; err_ = errno;
} }
@ -185,7 +193,9 @@ void FileInfo::dostat(bool link)
FileInfo & FileInfo::newFile(string const & path, 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; status_ = 0;
err_ = NoErr; err_ = NoErr;
dostat(link); dostat(link);
@ -308,7 +318,11 @@ bool FileInfo::isOK() const
bool FileInfo::isLink() const bool FileInfo::isLink() const
{ {
lyx::Assert(isOK()); lyx::Assert(isOK());
#ifdef S_ISLNK
return S_ISLNK(buf_.st_mode); return S_ISLNK(buf_.st_mode);
#else
return false;
#endif
} }

View File

@ -1247,6 +1247,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
bool LyXReadLink(string const & file, string & link, bool resolve) bool LyXReadLink(string const & file, string & link, bool resolve)
{ {
#ifdef HAVE_READLINK
char linkbuffer[512]; char linkbuffer[512];
// Should be PATH_MAX but that needs autconf support // Should be PATH_MAX but that needs autconf support
int const nRead = ::readlink(file.c_str(), int const nRead = ::readlink(file.c_str(),
@ -1259,6 +1260,9 @@ bool LyXReadLink(string const & file, string & link, bool resolve)
else else
link = linkbuffer; link = linkbuffer;
return true; return true;
#else
return false;
#endif
} }