From 13437ef9c8be4984ca23e40d9e51931b90736b63 Mon Sep 17 00:00:00 2001 From: mkoch Date: Sat, 17 Jul 2004 13:46:02 +0000 Subject: 2004-07-17 Mark Wielaard * gnu/java/nio/channels/FileChannelImpl.java (truncate): Only truncate when size is smaller. * java/io/RandomAccessFile.java (setLength): Use truncate for shrinking the file and seek plus write for expanding the file. 2004-07-17 Michael Koch * gnu/java/nio/channels/natFileChannelPosix.cc (implTruncate): Always save current position. Only reposition file pointer to where we started if not beyond new lenght. Reposition file pointer to file length if it points beyond the end of file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84868 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/gnu/java/nio/channels/FileChannelImpl.java | 4 +++- libjava/gnu/java/nio/channels/natFileChannelPosix.cc | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'libjava/gnu') diff --git a/libjava/gnu/java/nio/channels/FileChannelImpl.java b/libjava/gnu/java/nio/channels/FileChannelImpl.java index 8b3d0fc86b3..678e10f2349 100644 --- a/libjava/gnu/java/nio/channels/FileChannelImpl.java +++ b/libjava/gnu/java/nio/channels/FileChannelImpl.java @@ -422,7 +422,9 @@ public final class FileChannelImpl extends FileChannel if ((mode & WRITE) == 0) throw new NonWritableChannelException (); - implTruncate (size); + if (size < size ()) + implTruncate (size); + return this; } } diff --git a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc index b8f99378834..a2c1c7962b0 100644 --- a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc +++ b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc @@ -274,7 +274,10 @@ FileChannelImpl::implTruncate (jlong size) } else { - if (::ftruncate (fd, (off_t) pos)) + if (::ftruncate (fd, (off_t) size)) + throw new IOException (JvNewStringLatin1 (strerror (errno))); + if (pos > size + && ::lseek (fd, (off_t) size, SEEK_SET) == -1) throw new IOException (JvNewStringLatin1 (strerror (errno))); pos = size; } -- cgit v1.2.3