aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2007-04-03 01:07:56 +0000
committerTom Tromey <tromey@redhat.com>2007-04-03 01:07:56 +0000
commit1069c33a6fed5b9f0b7ecb8f05ea20f61eabe9ab (patch)
treead9821760baee795701af8312193f2a8bc64845f
parentc45d661f2a3cd65844ff4d6090c7bf6bfc42e10b (diff)
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=205157
* gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Extend file, when writing, if it is too short. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/redhat/gcc-4_1-branch@123449 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog6
-rw-r--r--libjava/gnu/java/nio/channels/natFileChannelPosix.cc14
2 files changed, 19 insertions, 1 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 94250382473..ec6f1272943 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,5 +1,11 @@
2007-04-02 Tom Tromey <tromey@redhat.com>
+ http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=205157
+ * gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Extend
+ file, when writing, if it is too short.
+
+2007-04-02 Tom Tromey <tromey@redhat.com>
+
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=233406
* gnu/java/net/natPlainSocketImplPosix.cc (create): Return if
already created.
diff --git a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc
index 4851403a8db..af03a0fe8b8 100644
--- a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc
+++ b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc
@@ -1,7 +1,7 @@
// natFileChannelImplPosix.cc - Native part of FileChannelImpl class.
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 Free Software Foundation
This file is part of libgcj.
@@ -501,6 +501,18 @@ FileChannelImpl::mapImpl (jchar mmode, jlong position, jint size)
{
prot = PROT_READ|PROT_WRITE;
flags = mmode == '+' ? MAP_SHARED : MAP_PRIVATE;
+
+ // If the file is too short, we must extend it. While using
+ // ftruncate() to extend a file is not portable in general, it
+ // should work on all systems where you can mmap() a file.
+ struct stat st;
+ if (fstat (fd, &st) == -1)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ if (position + size > st.st_size)
+ {
+ if (ftruncate (fd, position + size) == -1)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ }
}
jint page_size = ::getpagesize();
jint offset = position & ~(page_size-1);