I've currently got this nastiness in os_win32.h:
 #define S_ISLNK(m) 0
 #define lstat stat
 inline int readlink(const char *, char *, int) {return -1;}

Seems to me that the code that uses these should be rewritten to use a
HAVE_SYMBOLIC_LINKS macro. I append the affected pieces of code.

The question is, what's a reasonable configure test for the existence of
symbolic links? Should I just add tests that will generate HAVE_LSTAT and
HAVE_READLINK? If so, will these do the trick?

LYX_CHECK_DECL(lstat,unistd.h)
LYX_CHECK_DECL(readlink,unistd.h)

Angus


void FileInfo::dostat(bool link)
{
        string name(fname_);
#ifdef _WIN32
        // Win32 stat() doesn't dig trailing slashes
        if (name.at(name.size()-1) == '/')
                name.erase(name.size() -1);
#endif

#ifdef HAVE_SYMBOLIC_LINKS
        if (link)
                status_ = ::lstat(name.c_str(), &buf_);
        else
                status_ = ::stat(name.c_str(), &buf_);
#else
        status_ = ::stat(name.c_str(), &buf_);
#endif

        if (status_)
                err_ = errno;
}

bool FileInfo::isLink() const
{
        lyx::Assert(isOK());
#ifdef S_ISLNK
        return S_ISLNK(buf_.st_mode);
#else
 return 0;
}

bool LyXReadLink(string const & file, string & link, bool resolve)
{
#ifdef HAVE_SYMBOLIC_LINKS
        char linkbuffer[512];
        // Should be PATH_MAX but that needs autconf support
        int const nRead = ::readlink(file.c_str(),
                                     linkbuffer, sizeof(linkbuffer) - 1);
        if (nRead <= 0)
                return false;
        linkbuffer[nRead] = '\0'; // terminator
        if (resolve)
                link = MakeAbsPath(linkbuffer, OnlyPath(file));
        else
                link = linkbuffer;
        return true;
#else
        return false;
#endif
}

Note that lots of places within FileInfo use "#ifdef S_ISLNK", so I think
that's the right thing to do in FileInfo::isLink.


Reply via email to