[kaffe] CVS kaffe (robilad): Fixed RandomAccessfile regressions

Kaffe CVS cvs-commits at kaffe.org
Tue Sep 21 13:26:16 PDT 2004


PatchSet 5201 
Date: 2004/09/21 20:22:23
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Fixed RandomAccessfile regressions

2004-09-21  Noa Resare  <noa at resare.com>

        * libraries/clib/nio/FileChannelImpl.c
        (Java_gnu_java_nio_channels_FileChannelImpl_implTruncate):
        seek to new end of file when truncating the file (mirrors classpath)

Members: 
	ChangeLog:1.2756->1.2757 
	libraries/clib/nio/FileChannelImpl.c:1.6->1.7 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2756 kaffe/ChangeLog:1.2757
--- kaffe/ChangeLog:1.2756	Tue Sep 21 16:27:03 2004
+++ kaffe/ChangeLog	Tue Sep 21 20:22:23 2004
@@ -1,3 +1,9 @@
+2004-09-21  Noa Resare  <noa at resare.com>
+
+	* libraries/clib/nio/FileChannelImpl.c
+	(Java_gnu_java_nio_channels_FileChannelImpl_implTruncate):
+	seek to new end of file when truncating the file (mirrors classpath)
+
 2004-09-21  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/Makefile.am,
Index: kaffe/libraries/clib/nio/FileChannelImpl.c
diff -u kaffe/libraries/clib/nio/FileChannelImpl.c:1.6 kaffe/libraries/clib/nio/FileChannelImpl.c:1.7
--- kaffe/libraries/clib/nio/FileChannelImpl.c:1.6	Sun May 30 16:30:49 2004
+++ kaffe/libraries/clib/nio/FileChannelImpl.c	Tue Sep 21 20:22:25 2004
@@ -230,6 +230,7 @@
   int nativeFd = (int) getFD(env, filechannel);
   off_t fileSize;
   off_t new_length = (off_t)newSize;
+  off_t cur, oldPosition;
   int rc;
 
   rc = getFileSize(nativeFd, &fileSize);
@@ -241,6 +242,25 @@
   
   if (new_length < fileSize)
     {
+      /* Get the old file position */
+      rc = KLSEEK(nativeFd, 0, SEEK_CUR, &oldPosition);
+      if (rc != 0)
+        {
+          throwIOException(env, rc);
+          return;
+        }
+
+      if (oldPosition > new_length)
+	{
+	  /* Go to eof */
+	  rc = KLSEEK(nativeFd, new_length, SEEK_SET, &cur);
+	  if (rc != 0)
+	  {
+	    throwIOException(env, rc);
+	    return;
+	  }
+        }
+
       rc = KFTRUNCATE(nativeFd, new_length);
       if (rc != 0)
 	{
@@ -250,8 +270,6 @@
     }
   else
     {
-      off_t cur;
-      off_t oldPosition;
       char data = 0;
       ssize_t ret;
       




More information about the kaffe mailing list