diff options
| author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-24 17:48:41 +0000 |
|---|---|---|
| committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-24 17:48:41 +0000 |
| commit | 416ac64be4b4e75d7e228ef9b2bad6a363799ff9 (patch) | |
| tree | e662d090c42dfe798a34225b7ec886fdde1d8f2e /libjava/java/io/natFileDescriptorWin32.cc | |
| parent | 67f327824063863407e9d148f9cbe9eb5741a9cd (diff) | |
| download | gcc-416ac64be4b4e75d7e228ef9b2bad6a363799ff9.tar.gz | |
2002-07-24 Tom Tromey <tromey@redhat.com>
Tony Kimball <alk@pobox.com>
* java/io/natFileDescriptorWin32.cc (setLength): New method.
* java/io/natFileDescriptorPosix.cc (setLength): New method.
* java/io/RandomAccessFile.java (setLength): New method.
* java/io/natFileDescriptorEcos.cc (setLength): New method.
* java/io/FileDescriptor.java (setLength): New method.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55715 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io/natFileDescriptorWin32.cc')
| -rw-r--r-- | libjava/java/io/natFileDescriptorWin32.cc | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/libjava/java/io/natFileDescriptorWin32.cc b/libjava/java/io/natFileDescriptorWin32.cc index f72e39ce127..e004057ef91 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, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of libgcj. @@ -186,6 +186,58 @@ java::io::FileDescriptor::close (void) throw new IOException (JvNewStringLatin1 (winerr ())); } +void +java::io::FileDescriptor::setLength(jlong pos) +{ + LONG liOrigFilePointer; + LONG liNewFilePointer; + LONG liEndFilePointer; + + // Get the original file pointer. + if (SetFilePointer((HANDLE) fd, (LONG) 0, &liOrigFilePointer, + FILE_CURRENT) != (BOOL) 0 + && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + + // Get the length of the file. + if (SetFilePointer((HANDLE) fd, (LONG) 0, &liEndFilePointer, + FILE_END) != (BOOL) 0 + && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + + if ((jlong)liEndFilePointer == pos) + { + // Restore the file pointer. + if (liOrigFilePointer != liEndFilePointer) + { + if (SetFilePointer((HANDLE) fd, liOrigFilePointer, &liNewFilePointer, + FILE_BEGIN) != (BOOL) 0 + && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + } + return; + } + + // Seek to the new end of file. + if (SetFilePointer((HANDLE) fd, (LONG) pos, &liNewFilePointer, + FILE_BEGIN) != (BOOL) 0 + && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + + // Truncate the file at this point. + if (SetEndOfFile((HANDLE) fd) != (BOOL) 0 && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + + if (liOrigFilePointer < liNewFilePointer) + { + // Restore the file pointer. + if (SetFilePointer((HANDLE) fd, liOrigFilePointer, &liNewFilePointer, + FILE_BEGIN) != (BOOL) 0 + && (GetLastError() != NO_ERROR)) + throw new IOException (JvNewStringLatin1 (winerr ())); + } +} + jint java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc) { |
