]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxsum.cpp
fix warning on possibly(?) unused precompiled headers due to different -fPic settings...
[lyx.git] / src / support / lyxsum.cpp
index 165aff3273baaaed2039493dc5003421cfce3afb..568f7e78eeda1cfde3123f4cf76ef3d496424fbc 100644 (file)
 #include "support/FileName.h"
 
 #include <boost/crc.hpp>
+#include <boost/filesystem/operations.hpp>
 
 #include <algorithm>
 
 using std::endl;
 using std::string;
 
+namespace fs = boost::filesystem;
 
 // OK, this is ugly, but it is the only workaround I found to compile
 // with gcc (any version) on a system which uses a non-GNU toolchain.
@@ -37,10 +39,6 @@ template struct boost::detail::crc_table_t<32, 0x04C11DB7, true>;
 // are available. Order is faster to slowest.
 #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
 
-// Make sure we get modern version of mmap and friends with void*,
-// not `compatibility' version with caddr_t.
-#define _POSIX_C_SOURCE 199506L
-
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
@@ -126,8 +124,13 @@ unsigned long sum(FileName const & file)
        LYXERR(Debug::FILES) << "lyx::sum() using istreambuf_iterator (fast)"
                             << endl;
 
-       ifstream ifs(file.toFilesystemEncoding().c_str());
-       if (!ifs) return 0;
+       string filename = file.toFilesystemEncoding();
+       // a directory may be passed here so we need to test it. (bug 3622)
+       if (fs::is_directory(filename))
+               return 0;
+       ifstream ifs(filename.c_str());
+       if (!ifs)
+               return 0;
 
        istreambuf_iterator<char> beg(ifs);
        istreambuf_iterator<char> end;
@@ -145,8 +148,13 @@ unsigned long sum(FileName const & file)
                << "lyx::sum() using istream_iterator (slow as a snail)"
                << endl;
 
-       ifstream ifs(file.toFilesystemEncoding().c_str());
-       if (!ifs) return 0;
+       string filename = file.toFilesystemEncoding();
+       // a directory may be passed here so we need to test it. (bug 3622)
+       if (fs::is_directory(filename))
+               return 0;
+       ifstream ifs(filename.c_str());
+       if (!ifs)
+               return 0;
 
        ifs.unsetf(ios::skipws);
        istream_iterator<char> beg(ifs);