Commit 8d6a4375 by Tom Tromey Committed by Tom Tromey

RandomAccessFile.java (seek): Let seek go past end of file.

	* 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.

From-SVN: r44586
parent ead4cf34
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> 2001-08-02 Martin Kahlert <martin.kahlert@infineon.com>
* jni.cc (JNI_CreateJavaVM): Call _Jv_JNI_Init in order * jni.cc (JNI_CreateJavaVM): Call _Jv_JNI_Init in order
......
// FileDescriptor.java - Open file or device // 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. This file is part of libgcj.
...@@ -54,7 +54,11 @@ public final class FileDescriptor ...@@ -54,7 +54,11 @@ public final class FileDescriptor
native void write (byte[] b, int offset, int len) native void write (byte[] b, int offset, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException; throws IOException, NullPointerException, IndexOutOfBoundsException;
native void close () throws IOException; 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 length () throws IOException;
native long getFilePointer () throws IOException; native long getFilePointer () throws IOException;
native int read () throws IOException; native int read () throws IOException;
......
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -88,6 +88,6 @@ public class FileInputStream extends InputStream ...@@ -88,6 +88,6 @@ public class FileInputStream extends InputStream
public long skip(long n) throws IOException public long skip(long n) throws IOException
{ {
return fd.seek(n, FileDescriptor.CUR); return n <= 0 ? 0 : fd.seek(n, FileDescriptor.CUR, true);
} }
} }
// RandomAccessFile.java // RandomAccessFile.java
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -161,12 +161,12 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -161,12 +161,12 @@ public class RandomAccessFile implements DataOutput, DataInput
public void seek (long pos) throws IOException 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 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 public void write (int oneByte) throws IOException
......
// natFileDescriptor.cc - Native part of FileDescriptor class. // 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. This file is part of libgcj.
...@@ -88,16 +88,9 @@ java::io::FileDescriptor::close (void) ...@@ -88,16 +88,9 @@ java::io::FileDescriptor::close (void)
} }
jint jint
java::io::FileDescriptor::seek (jlong pos, jint whence) java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
{ {
JvAssert (whence == SET || whence == CUR); 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; return 0;
} }
......
...@@ -177,15 +177,19 @@ java::io::FileDescriptor::close (void) ...@@ -177,15 +177,19 @@ java::io::FileDescriptor::close (void)
} }
jint 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); JvAssert (whence == SET || whence == CUR);
jlong len = length (); jlong len = length ();
jlong here = getFilePointer (); jlong here = getFilePointer ();
if ((whence == SET && pos > len) || (whence == CUR && here + pos > len)) if (eof_trunc
throw new EOFException; && ((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); off_t r = ::lseek (fd, (off_t) pos, whence == SET ? SEEK_SET : SEEK_CUR);
if (r == -1) if (r == -1)
......
// natFileDescriptorWin32.cc - Native part of FileDescriptor class. // 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. This file is part of libgcj.
...@@ -171,15 +171,19 @@ java::io::FileDescriptor::close (void) ...@@ -171,15 +171,19 @@ java::io::FileDescriptor::close (void)
} }
jint 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); JvAssert (whence == SET || whence == CUR);
jlong len = length(); jlong len = length();
jlong here = getFilePointer(); jlong here = getFilePointer();
if ((whence == SET && pos > len) || (whence == CUR && here + pos > len)) if (eof_trunc
throw new EOFException; && ((whence == SET && pos > len) || (whence == CUR && here + pos > len)))
{
whence = SET;
pos = len;
}
LONG high = pos >> 32; LONG high = pos >> 32;
DWORD low = SetFilePointer ((HANDLE)fd, (DWORD)(0xffffffff & pos), &high, whence == SET ? FILE_BEGIN : FILE_CURRENT); DWORD low = SetFilePointer ((HANDLE)fd, (DWORD)(0xffffffff & pos), &high, whence == SET ? FILE_BEGIN : FILE_CURRENT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment