Commits

Mathias Panzenböck  committed 4e8600e

bugfix in linux specific code

  • Participants
  • Parent commits 074fa59

Comments (0)

Files changed (1)

File libvpk/src/file_io.cpp

 #include <unistd.h>
 #include <sys/stat.h>
 
+#if (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE) && defined(__linux__)
+#include <sys/sendfile.h>
+#endif
+
 Vpk::FileIO &Vpk::FileIO::operator = (const FileIO &reader) {
 	close();
 	if (reader.m_stream) {
 	}
 
 size_t Vpk::FileIO::readSome(FileIO &dest, size_t size) {
-#if (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE) && defined(__LINUX__)
+#if (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE) && defined(__linux__)
 	size_t bufsize = buffered();
 	size_t left = std::min(bufsize, size);
 	VPK_READ_SOME;
-	if (left > 0) {
+	if (left != 0) throw IOError(EOF);
+	if (bufsize < size) {
 		dest.flush();
-		ssize_t count = sendfile(::fileno(dest.m_stream), ::fileno(m_stream), left);
+		ssize_t count = sendfile(
+			::fileno(dest.m_stream),
+			::fileno(m_stream), 0, size - bufsize);
 		if (count < 0) {
 			throw IOError(errno);
 		}