diff options
author | Tom Tromey <tromey@redhat.com> | 2007-04-03 01:05:50 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-04-03 01:05:50 +0000 |
commit | 8854e14c61b79559e4c3cb5c251149071bbfee45 (patch) | |
tree | 9ae78a4b8566fce3477c8dc37e366d1f366630d5 /libjava/gnu/java | |
parent | cb7ad97b41523821a88dd4a4943fa62507927fd6 (diff) | |
download | gcc-8854e14c61b79559e4c3cb5c251149071bbfee45.zip gcc-8854e14c61b79559e4c3cb5c251149071bbfee45.tar.gz gcc-8854e14c61b79559e4c3cb5c251149071bbfee45.tar.bz2 |
natFileChannelPosix.cc (mapImpl): Extend file, when writing, if it is too short.
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.
From-SVN: r123447
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r-- | libjava/gnu/java/nio/channels/natFileChannelPosix.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc index 52caf82..e05904c 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. @@ -499,6 +499,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); |