summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-02 23:46:39 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-02 23:46:39 +0000
commitb981695a68c06694a48068337ed21f5ac380c9f2 (patch)
tree9a4a339f33e52b784286ab24c2d8b29c0c4f6d69 /libjava
parent815df046cd0c9377ab9848eec1ff73e9d52e7674 (diff)
downloadgcc-b981695a68c06694a48068337ed21f5ac380c9f2.tar.gz
* java/io/RandomAccessFile.java (seek): Let seek go past end of
file. (skipBytes): Don't fail if seeking past end of file. * java/io/FileInputStream.java (skip): Don't fail if seeking past end of file. * java/io/natFileDescriptorWin32.cc (seek): Handle `eof_trunc' argument. * java/io/natFileDescriptorEcos.cc (seek): Handle `eof_trunc' argument. * java/io/natFileDescriptorPosix.cc (seek): Handle `eof_trunc' argument. * java/io/FileDescriptor.java (seek): Added `eof_trunc' argument. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44586 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog15
-rw-r--r--libjava/java/io/FileDescriptor.java8
-rw-r--r--libjava/java/io/FileInputStream.java4
-rw-r--r--libjava/java/io/RandomAccessFile.java6
-rw-r--r--libjava/java/io/natFileDescriptorEcos.cc11
-rw-r--r--libjava/java/io/natFileDescriptorPosix.cc10
-rw-r--r--libjava/java/io/natFileDescriptorWin32.cc12
7 files changed, 43 insertions, 23 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index e410068bde4..5bdccf0bbf4 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,18 @@
+2001-08-02 Tom Tromey <tromey@redhat.com>
+
+ * java/io/RandomAccessFile.java (seek): Let seek go past end of
+ file.
+ (skipBytes): Don't fail if seeking past end of file.
+ * java/io/FileInputStream.java (skip): Don't fail if seeking past
+ end of file.
+ * java/io/natFileDescriptorWin32.cc (seek): Handle `eof_trunc'
+ argument.
+ * java/io/natFileDescriptorEcos.cc (seek): Handle `eof_trunc'
+ argument.
+ * java/io/natFileDescriptorPosix.cc (seek): Handle `eof_trunc'
+ argument.
+ * java/io/FileDescriptor.java (seek): Added `eof_trunc' argument.
+
2001-08-02 Martin Kahlert <martin.kahlert@infineon.com>
* jni.cc (JNI_CreateJavaVM): Call _Jv_JNI_Init in order
diff --git a/libjava/java/io/FileDescriptor.java b/libjava/java/io/FileDescriptor.java
index 493f14cf280..8afcda4768f 100644
--- a/libjava/java/io/FileDescriptor.java
+++ b/libjava/java/io/FileDescriptor.java
@@ -1,6 +1,6 @@
// FileDescriptor.java - Open file or device
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -54,7 +54,11 @@ public final class FileDescriptor
native void write (byte[] b, int offset, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException;
native void close () throws IOException;
- native int seek (long pos, int whence) throws IOException;
+ // EOF_TRUNC is true if a request to seek past the end of file
+ // should actually stop at the end of file. If false, then a seek
+ // past the end is ok (and if a subsequent write occurs the file
+ // will grow).
+ native int seek (long pos, int whence, boolean eof_trunc) throws IOException;
native long length () throws IOException;
native long getFilePointer () throws IOException;
native int read () throws IOException;
diff --git a/libjava/java/io/FileInputStream.java b/libjava/java/io/FileInputStream.java
index 67d4842f4f8..9d0d0133b9c 100644
--- a/libjava/java/io/FileInputStream.java
+++ b/libjava/java/io/FileInputStream.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj.
@@ -88,6 +88,6 @@ public class FileInputStream extends InputStream
public long skip(long n) throws IOException
{
- return fd.seek(n, FileDescriptor.CUR);
+ return n <= 0 ? 0 : fd.seek(n, FileDescriptor.CUR, true);
}
}
diff --git a/libjava/java/io/RandomAccessFile.java b/libjava/java/io/RandomAccessFile.java
index 9a0bf807202..418974c091e 100644
--- a/libjava/java/io/RandomAccessFile.java
+++ b/libjava/java/io/RandomAccessFile.java
@@ -1,6 +1,6 @@
// RandomAccessFile.java
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj.
@@ -161,12 +161,12 @@ public class RandomAccessFile implements DataOutput, DataInput
public void seek (long pos) throws IOException
{
- fd.seek(pos, FileDescriptor.SET);
+ fd.seek(pos, FileDescriptor.SET, false);
}
public int skipBytes (int count) throws IOException
{
- return fd.seek(count, FileDescriptor.CUR);
+ return count <= 0 ? 0 : fd.seek(count, FileDescriptor.CUR, true);
}
public void write (int oneByte) throws IOException
diff --git a/libjava/java/io/natFileDescriptorEcos.cc b/libjava/java/io/natFileDescriptorEcos.cc
index 43574df8893..a66bf739d35 100644
--- a/libjava/java/io/natFileDescriptorEcos.cc
+++ b/libjava/java/io/natFileDescriptorEcos.cc
@@ -1,6 +1,6 @@
// natFileDescriptor.cc - Native part of FileDescriptor class.
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj.
@@ -88,16 +88,9 @@ java::io::FileDescriptor::close (void)
}
jint
-java::io::FileDescriptor::seek (jlong pos, jint whence)
+java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
{
JvAssert (whence == SET || whence == CUR);
-
- jlong len = length ();
- jlong here = getFilePointer ();
-
- if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
- throw new EOFException;
-
return 0;
}
diff --git a/libjava/java/io/natFileDescriptorPosix.cc b/libjava/java/io/natFileDescriptorPosix.cc
index 4e05cfe1df3..ad1c1cdd048 100644
--- a/libjava/java/io/natFileDescriptorPosix.cc
+++ b/libjava/java/io/natFileDescriptorPosix.cc
@@ -177,15 +177,19 @@ java::io::FileDescriptor::close (void)
}
jint
-java::io::FileDescriptor::seek (jlong pos, jint whence)
+java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
{
JvAssert (whence == SET || whence == CUR);
jlong len = length ();
jlong here = getFilePointer ();
- if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
- throw new EOFException;
+ if (eof_trunc
+ && ((whence == SET && pos > len) || (whence == CUR && here + pos > len)))
+ {
+ whence = SET;
+ pos = len;
+ }
off_t r = ::lseek (fd, (off_t) pos, whence == SET ? SEEK_SET : SEEK_CUR);
if (r == -1)
diff --git a/libjava/java/io/natFileDescriptorWin32.cc b/libjava/java/io/natFileDescriptorWin32.cc
index 3f8ae76b269..c0e33e2a2ae 100644
--- a/libjava/java/io/natFileDescriptorWin32.cc
+++ b/libjava/java/io/natFileDescriptorWin32.cc
@@ -1,6 +1,6 @@
// natFileDescriptorWin32.cc - Native part of FileDescriptor class.
-/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001 Red Hat, Inc.
This file is part of libgcj.
@@ -171,15 +171,19 @@ java::io::FileDescriptor::close (void)
}
jint
-java::io::FileDescriptor::seek (jlong pos, jint whence)
+java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
{
JvAssert (whence == SET || whence == CUR);
jlong len = length();
jlong here = getFilePointer();
- if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
- throw new EOFException;
+ if (eof_trunc
+ && ((whence == SET && pos > len) || (whence == CUR && here + pos > len)))
+ {
+ whence = SET;
+ pos = len;
+ }
LONG high = pos >> 32;
DWORD low = SetFilePointer ((HANDLE)fd, (DWORD)(0xffffffff & pos), &high, whence == SET ? FILE_BEGIN : FILE_CURRENT);