← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2808: Fix hashing under *nix

 

------------------------------------------------------------
revno: 2808
fixes bug: https://launchpad.net/bugs/913566
author: Razzloss <razzloss@xxxxxxxxx>
committer: eMTee <emtee11@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Tue 2012-01-10 12:21:22 +0100
message:
  Fix hashing under *nix
modified:
  dcpp/FileReader.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/FileReader.cpp'
--- dcpp/FileReader.cpp	2012-01-01 14:22:32 +0000
+++ dcpp/FileReader.cpp	2012-01-10 11:21:22 +0000
@@ -229,6 +229,10 @@
 #include <sys/mman.h> // mmap, munmap, madvise
 #include <signal.h>  // for handling read errors from previous trio
 #include <setjmp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 
 size_t FileReader::readDirect(const string& file, const DataCallback& callback) {
 	return READ_FAILED;
@@ -251,8 +255,15 @@
 		return READ_FAILED;
 	}
 
+	struct stat statbuf;
+	if (fstat(fd, &statbuf) == -1) {
+		dcdebug("Error opening file %s: %s\n", filename.c_str(), Util::translateError(errno).c_str());
+		close(fd);
+		return READ_FAILED;
+	}
+
 	int64_t pos = 0;
-	auto size =0;
+	auto size = statbuf.st_size;
 
 	// Prepare and setup a signal handler in case of SIGBUS during mmapped file reads.
 	// SIGBUS can be sent when the file is truncated or in case of read errors.