#include <config.h>
-#include "support/lyxlib.h"
#include "support/debug.h"
-#include "support/FileName.h"
#include <boost/crc.hpp>
#include <algorithm>
#include <iomanip>
-using std::endl;
-using std::string;
+using namespace std;
// 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.
namespace lyx {
namespace support {
-unsigned long sum(FileName const & file)
+unsigned long sum(char const * file)
{
- LYXERR(Debug::FILES, "lyx::sum() using mmap (lightning fast)");
+ //LYXERR(Debug::FILES, "lyx::sum() using mmap (lightning fast)");
- int fd = open(file.toFilesystemEncoding().c_str(), O_RDONLY);
+ int fd = open(file, O_RDONLY);
if (!fd)
return 0;
#include <fstream>
#include <iterator>
-
namespace {
template<typename InputIterator>
unsigned long do_crc(InputIterator first, InputIterator last)
{
boost::crc_32_type crc;
- crc = std::for_each(first, last, crc);
+ crc = for_each(first, last, crc);
return crc.checksum();
}
namespace lyx {
namespace support {
-using std::ifstream;
-#if HAVE_DECL_ISTREAMBUF_ITERATOR
-using std::istreambuf_iterator;
-unsigned long sum(FileName const & file)
+unsigned long sum(char const * file)
{
- LYXERR(Debug::FILES, "lyx::sum() using istreambuf_iterator (fast)");
-
- // a directory may be passed here so we need to test it. (bug 3622)
- if (file.isDirectory())
- return 0;
- string filename = file.toFilesystemEncoding();
- ifstream ifs(filename.c_str(), std::ios_base::in | std::ios_base::binary);
+ ifstream ifs(file, ios_base::in | ios_base::binary);
if (!ifs)
return 0;
+#if HAVE_DECL_ISTREAMBUF_ITERATOR
+ //LYXERR(Debug::FILES, "lyx::sum() using istreambuf_iterator (fast)");
istreambuf_iterator<char> beg(ifs);
istreambuf_iterator<char> end;
-
- return do_crc(beg,end);
-}
#else
-
-using std::istream_iterator;
-using std::ios;
-
-unsigned long sum(FileName const & file)
-{
- LYXERR(Debug::FILES, "lyx::sum() using istream_iterator (slow as a snail)");
-
- // a directory may be passed here so we need to test it. (bug 3622)
- if (file.isDirectory())
- return 0;
-
- string filename = file.toFilesystemEncoding();
- ifstream ifs(filename.c_str(), std::ios_base::in | std::ios_base::binary);
- if (!ifs)
- return 0;
-
+ //LYXERR(Debug::FILES, "lyx::sum() using istream_iterator (slow as a snail)");
ifs.unsetf(ios::skipws);
istream_iterator<char> beg(ifs);
istream_iterator<char> end;
+#endif
return do_crc(beg,end);
}
-#endif
} // namespace support
} // namespace lyx