From f1a10948c7e4caf5a6d9d53b4b3ad99580fc1cea Mon Sep 17 00:00:00 2001 From: Elliott Hughes <enh@google.com> Date: Tue, 24 May 2011 16:41:16 -0700 Subject: Fix a couple of FileChannel bugs. FileChannel.read's non-readv(2) overload shares java.io's weird non-Unix "-1 at EOF" behavior. The readv(2) overloads already had that, but they had a bug where they'd claim to have copied more into a buffer than they actually had. No new tests because these were found by existing Harmony unit tests. Change-Id: Ia267e5834fd360d71becdd7d1bdd838d03ea6532 --- luni/src/main/java/java/nio/FileChannelImpl.java | 3 +++ luni/src/main/java/java/nio/IoVec.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'luni') diff --git a/luni/src/main/java/java/nio/FileChannelImpl.java b/luni/src/main/java/java/nio/FileChannelImpl.java index 379c99f..53c1e4d 100644 --- a/luni/src/main/java/java/nio/FileChannelImpl.java +++ b/luni/src/main/java/java/nio/FileChannelImpl.java @@ -297,6 +297,9 @@ final class FileChannelImpl extends FileChannel { begin(); try { bytesRead = Libcore.os.read(fd, buffer); + if (bytesRead == 0) { + bytesRead = -1; + } } catch (ErrnoException errnoException) { if (errnoException.errno == EAGAIN) { // We don't throw if we try to read from an empty non-blocking pipe. diff --git a/luni/src/main/java/java/nio/IoVec.java b/luni/src/main/java/java/nio/IoVec.java index 948e658..e548548 100644 --- a/luni/src/main/java/java/nio/IoVec.java +++ b/luni/src/main/java/java/nio/IoVec.java @@ -92,7 +92,7 @@ final class IoVec { b.position(b.limit()); byteCount -= byteCounts[i]; } else { - b.position((direction == Direction.WRITEV ? b.position() : 0) + byteCounts[i]); + b.position((direction == Direction.WRITEV ? b.position() : 0) + byteCount); byteCount = 0; } } -- cgit v1.1