summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-05-24 17:27:57 -0700
committerElliott Hughes <enh@google.com>2011-05-24 17:27:57 -0700
commitc03e4ba8cd93513aabda061b00d516b54717c5fb (patch)
tree4deaa23744035ea2d76861b9bb09ee54b06e1c52 /luni
parentad98d26fe40962b37ed3992a6106f7e673b72450 (diff)
downloadlibcore-c03e4ba8cd93513aabda061b00d516b54717c5fb.zip
libcore-c03e4ba8cd93513aabda061b00d516b54717c5fb.tar.gz
libcore-c03e4ba8cd93513aabda061b00d516b54717c5fb.tar.bz2
Fix a bug in FileChannel.map.
Found by a Harmony test. Change-Id: I1f2ba191242dd6236549e6ed4ef77021ad7ae628
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/nio/FileChannelImpl.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/luni/src/main/java/java/nio/FileChannelImpl.java b/luni/src/main/java/java/nio/FileChannelImpl.java
index 53c1e4d..bc13efd 100644
--- a/luni/src/main/java/java/nio/FileChannelImpl.java
+++ b/luni/src/main/java/java/nio/FileChannelImpl.java
@@ -228,7 +228,13 @@ final class FileChannelImpl extends FileChannel {
throw new NonReadableChannelException();
}
if (position + size > size()) {
- truncate(position + size);
+ // We can't defer to FileChannel.truncate because that will only make a file shorter,
+ // and we only care about making our backing file longer here.
+ try {
+ Libcore.os.ftruncate(fd, position + size);
+ } catch (ErrnoException errnoException) {
+ throw errnoException.rethrowAsIOException();
+ }
}
long alignment = position - position % Libcore.os.sysconf(_SC_PAGE_SIZE);
int offset = (int) (position - alignment);