summaryrefslogtreecommitdiff
path: root/native/jni/java-io
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/java-io')
-rw-r--r--native/jni/java-io/.cvsignore8
-rw-r--r--native/jni/java-io/java_io_File.c554
-rw-r--r--native/jni/java-io/java_io_FileDescriptor.c74
-rw-r--r--native/jni/java-io/java_io_FileInputStream.c103
-rw-r--r--native/jni/java-io/java_io_FileOutputStream.c92
-rw-r--r--native/jni/java-io/java_io_ObjectInputStream.c329
-rw-r--r--native/jni/java-io/java_io_ObjectOutputStream.c308
-rw-r--r--native/jni/java-io/java_io_RandomAccessFile.c180
-rw-r--r--native/jni/java-io/javaio.c193
-rw-r--r--native/jni/java-io/javaio.h45
10 files changed, 1886 insertions, 0 deletions
diff --git a/native/jni/java-io/.cvsignore b/native/jni/java-io/.cvsignore
new file mode 100644
index 000000000..e9f2658a6
--- /dev/null
+++ b/native/jni/java-io/.cvsignore
@@ -0,0 +1,8 @@
+*.o
+*.a
+*.lo
+*.la
+.libs
+.deps
+Makefile
+Makefile.in
diff --git a/native/jni/java-io/java_io_File.c b/native/jni/java-io/java_io_File.c
new file mode 100644
index 000000000..1c2760327
--- /dev/null
+++ b/native/jni/java-io/java_io_File.c
@@ -0,0 +1,554 @@
+/* File.c - Native methods for java.io.File class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <utime.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#include <jni.h>
+#include <jcl.h>
+#include "javaio.h"
+
+#include "java_io_File.h"
+
+/*************************************************************************/
+
+/*
+ * Method to create an empty file
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_createInternal(JNIEnv *env, jclass clazz, jstring name)
+{
+ const char *fname;
+ int fd;
+
+ fname = JCL_jstring_to_cstring(env, name);
+ if (!fname)
+ return(0);
+
+ fd = open(fname, O_CREAT|O_EXCL|O_RDWR, 0777);
+ if (fd == -1)
+ {
+ if (errno != EEXIST)
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+ return(0);
+ }
+
+ close(fd);
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if we have read permission on a file
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_canReadInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ int fd;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ /* The lazy man's way out. We actually do open the file for reading
+ briefly to verify it can be done */
+ fd = open(fname, O_RDONLY);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (fd == -1)
+ return(0);
+
+ close(fd);
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if we have write permission on a file
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_canWriteInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ int fd;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ /* The lazy man's way out. We actually do open the file for writing
+ briefly to verify it can be done */
+ fd = open(fname, O_RDWR);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (fd == -1)
+ return(0);
+
+ close(fd);
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method makes a file read only
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_setReadOnlyInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ mode_t newmode;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = stat(fname, &buf);
+
+ if (rc == -1)
+ {
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+ return(0);
+ }
+
+ newmode = buf.st_mode;
+ newmode = newmode & (~(S_IWRITE|S_IWGRP|S_IWOTH));
+
+ rc = chmod(fname, newmode);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file exists
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_existsInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = stat(fname, &buf);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file is a "plain" file. That is, not
+ * a directory, pipe, etc.
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_isFileInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = lstat(fname, &buf);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ if (S_ISREG(buf.st_mode))
+ return(1);
+ else
+ return(0);
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file is a directory or not.
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_isDirectoryInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = lstat(fname, &buf);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ if (S_ISDIR(buf.st_mode))
+ return(1);
+ else
+ return(0);
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns the length of the file
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_File_lengthInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = stat(fname, &buf);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+
+ return(buf.st_size);
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns the modification date of the file
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_File_lastModifiedInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ struct stat buf;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = stat(fname, &buf);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+
+ return(buf.st_mtime);
+}
+
+/*************************************************************************/
+
+/*
+ * This method sets the modificatino date of the file
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_setLastModifiedInternal(JNIEnv *env, jobject obj,
+ jstring name, jlong newtime)
+{
+ const char *fname;
+ struct stat buf;
+ struct utimbuf ut;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = stat(fname, &buf);
+
+ if (rc == -1)
+ {
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+ return(0);
+ }
+
+ ut.actime = buf.st_atime;
+ ut.modtime = buf.st_mtime;
+
+ rc = utime(fname, &ut);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method deletes a file (actually a name for a file - additional
+ * linke could exist).
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_deleteInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = unlink(fname);
+ if (rc == -1)
+ rc = rmdir(fname);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method creates a directory
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_mkdirInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ const char *fname;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ fname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!fname)
+ return(0);
+
+ rc = mkdir(fname, 0777);
+ (*env)->ReleaseStringUTFChars(env, name, fname);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method creates a directory
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_renameToInternal(JNIEnv *env, jobject obj, jstring t, jstring d)
+{
+ const char *target, *destination;
+ int rc;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ target = (*env)->GetStringUTFChars(env, t, 0);
+ if (!target)
+ return(0);
+
+ destination = (*env)->GetStringUTFChars(env, d, 0);
+ if (!destination)
+ {
+ (*env)->ReleaseStringUTFChars(env, t, target);
+ return(0);
+ }
+
+ rc = rename(target, destination);
+ (*env)->ReleaseStringUTFChars(env, t, target);
+ (*env)->ReleaseStringUTFChars(env, d, destination);
+
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns an array of String representing all the files
+ * in a directory except "." and ".."
+ */
+
+JNIEXPORT jobjectArray JNICALL
+Java_java_io_File_listInternal(JNIEnv *env, jobject obj, jstring name)
+{
+ static jclass str_clazz = 0;
+ int realloc_size = 10;
+ const char *dirname;
+ char **filelist;
+ jobjectArray retarray;
+ DIR *dir;
+ struct dirent *dirent;
+ int i, j;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ dirname = (*env)->GetStringUTFChars(env, name, 0);
+ if (!dirname)
+ return(0);
+
+ /* Read the files from the directory */
+ filelist = (char **)JCL_malloc(env, sizeof(char *) * realloc_size);
+ //filelist = (char **)malloc(sizeof(char *) * realloc_size);
+ dir = opendir(dirname);
+ (*env)->ReleaseStringUTFChars(env, name, dirname);
+ if (!filelist || !dir)
+ return(0);
+
+ for (i = 0;;)
+ {
+ dirent = readdir(dir);
+ if (!dirent)
+ break;
+
+ if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, ".."))
+ continue;
+
+ /* Allocate more memory if necessary */
+ if ((((i + 1) % realloc_size) == 0) && (i != 0))
+ {
+ char **newlist;
+
+ newlist = JCL_realloc(env, filelist, ((i + 1) + realloc_size) *
+ sizeof(char *));
+ //newlist = realloc(filelist, (i + 1) + realloc_size);
+ if (!filelist)
+ {
+ free(filelist);
+ return(0);
+ }
+ filelist = newlist;
+ }
+
+ filelist[i] = strdup(dirent->d_name);
+ ++i;
+ }
+ closedir(dir);
+
+ /* Did we find anything? */
+ if (i == 0)
+ {
+ free(filelist);
+ return(0);
+ }
+
+ /* Now put the list of files into a Java String array and return it */
+ str_clazz = (*env)->FindClass(env, "java/lang/String");
+ if (!str_clazz)
+ {
+ free(filelist);
+ return(0);
+ }
+
+ retarray = (*env)->NewObjectArray(env, i, str_clazz, 0);
+ if (!retarray)
+ {
+ free(filelist);
+ return(0);
+ }
+
+ for (j = 0; j < i; j++)
+ {
+ jstring str;
+
+ str = (*env)->NewStringUTF(env, filelist[j]);
+ if (!str)
+ {
+ /* We don't clean up everything here, but if this failed,
+ something serious happened anyway */
+ free(filelist);
+ return(0);
+ }
+
+ (*env)->SetObjectArrayElement(env, retarray, j, str);
+ }
+
+ return(retarray);
+}
+
diff --git a/native/jni/java-io/java_io_FileDescriptor.c b/native/jni/java-io/java_io_FileDescriptor.c
new file mode 100644
index 000000000..acab74a97
--- /dev/null
+++ b/native/jni/java-io/java_io_FileDescriptor.c
@@ -0,0 +1,74 @@
+/* FileDescriptor.c - Native methods for java.io.FileDescriptor class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <jni.h>
+#include <jcl.h>
+#include "java_io_FileDescriptor.h"
+#include "javaio.h"
+
+/*************************************************************************/
+
+/*
+ * Method to force all data for this descriptor to be flushed to disk
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_FileDescriptor_syncInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ int rc;
+
+ rc = fsync(fd);
+ if (rc == -1)
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+}
+
+/*************************************************************************/
+
+/*
+ * Method to check if a given descriptor is valid.
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_FileDescriptor_validInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ int rc;
+
+ /* Try a miscellaneous operation */
+ rc = fcntl(fd, F_GETFL, 0);
+ if (rc == -1)
+ return(0);
+ else
+ return(1);
+}
+
diff --git a/native/jni/java-io/java_io_FileInputStream.c b/native/jni/java-io/java_io_FileInputStream.c
new file mode 100644
index 000000000..38c612dd1
--- /dev/null
+++ b/native/jni/java-io/java_io_FileInputStream.c
@@ -0,0 +1,103 @@
+/* FileInputStream.c - Native methods for java.io.FileInputStream class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <jni.h>
+#include <jcl.h>
+#include "javaio.h"
+
+#include "java_io_FileInputStream.h"
+
+/*************************************************************************/
+
+/*
+ * Returns the length of the file being read.
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_FileInputStream_getFileLength(JNIEnv *env, jobject obj, jint fd)
+{
+ return(_javaio_get_file_length(env, fd));
+}
+
+/*************************************************************************/
+
+/*
+ * Method to skip bytes in a file
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_FileInputStream_skipInternal(JNIEnv *env, jobject obj, jint fd,
+ jlong num_bytes)
+{
+ return(_javaio_skip_bytes(env, fd, num_bytes));
+}
+
+/*************************************************************************/
+
+/*
+ * Opens the file for reading
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_FileInputStream_open(JNIEnv *env, jobject obj, jstring name)
+{
+ return(_javaio_open(env, name, O_RDONLY));
+}
+
+/*************************************************************************/
+
+/*
+ * Reads bytes from the file
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_FileInputStream_readInternal(JNIEnv *env, jobject obj, jint fd,
+ jarray buf, jint offset, jint len)
+{
+ return(_javaio_read(env, obj, fd, buf, offset, len));
+}
+
+/*************************************************************************/
+
+/*
+ * Closes the file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_FileInputStream_closeInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ _javaio_close(env, fd);
+}
+
+
diff --git a/native/jni/java-io/java_io_FileOutputStream.c b/native/jni/java-io/java_io_FileOutputStream.c
new file mode 100644
index 000000000..0cddb3006
--- /dev/null
+++ b/native/jni/java-io/java_io_FileOutputStream.c
@@ -0,0 +1,92 @@
+/* FileOutputStream.c - Native methods for java.io.FileOutputStream class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <jni.h>
+#include <jcl.h>
+#include "javaio.h"
+
+#include "java_io_FileOutputStream.h"
+
+/*************************************************************************/
+
+/*
+ * Opens the file for writing
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_FileOutputStream_open(JNIEnv *env, jobject obj, jstring name,
+ jboolean append)
+{
+ int fd = _javaio_open(env, name, O_RDWR|O_CREAT);
+
+ if ((append) && (fd != -1))
+ {
+ int rc = lseek(fd, 0, SEEK_END);
+ if (rc == -1)
+ {
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+ close(fd);
+ return(-1);
+ }
+ }
+
+ return(fd);
+}
+
+/*************************************************************************/
+
+/*
+ * Write bytes to file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_FileOutputStream_writeInternal(JNIEnv *env, jobject obj, jint fd,
+ jarray buf, jint offset, jint len)
+{
+ _javaio_write(env, obj, fd, buf, offset, len);
+}
+
+/*************************************************************************/
+
+/*
+ * Closes the file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_FileOutputStream_closeInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ _javaio_close(env, fd);
+}
+
+
diff --git a/native/jni/java-io/java_io_ObjectInputStream.c b/native/jni/java-io/java_io_ObjectInputStream.c
new file mode 100644
index 000000000..c5dd5617a
--- /dev/null
+++ b/native/jni/java-io/java_io_ObjectInputStream.c
@@ -0,0 +1,329 @@
+/* java_io_ObjectInputStream.c -- Native methods for ObjectInputStream class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+/* TODO: check exceptions */
+/* comments */
+
+#include <jni.h>
+#include <jcl.h>
+#include "java_io_ObjectInputStream.h"
+
+JNIEXPORT jobject JNICALL
+Java_java_io_ObjectInputStream_currentClassLoader( JNIEnv * env,
+ jclass clazz,
+ jobject loader )
+{
+ jmethodID id = (*env)->GetMethodID( env,
+ (*env)->GetObjectClass( env, loader ),
+ "currentClassLoader",
+ "()Ljava/lang/ClassLoader;" );
+
+ if( id == NULL )
+ return NULL;
+
+ (*env)->CallObjectMethod( env, loader, id );
+ return loader;
+}
+
+
+JNIEXPORT jobject JNICALL
+Java_java_io_ObjectInputStream_allocateObject( JNIEnv * env,
+ jobject self,
+ jclass clazz )
+{
+ return (*env)->AllocObject( env, clazz );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_callConstructor( JNIEnv * env,
+ jclass clazz,
+ jclass constr_class,
+ jobject obj )
+{
+ jmethodID id = (*env)->GetMethodID( env, constr_class,
+ "<init>", "()V" );
+ if( id == NULL )
+ return;
+
+ (*env)->CallNonvirtualVoidMethod( env, obj, constr_class, id );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_callReadMethod( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jclass clazz )
+{
+ jmethodID id = (*env)->GetMethodID( env, clazz,
+ "readObject",
+ "(Ljava/io/ObjectInputStream;)V" );
+
+ if( id == NULL )
+ return;
+
+ (*env)->CallNonvirtualVoidMethod( env, obj, clazz, id, self );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setBooleanField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jboolean val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "Z" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetBooleanField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setByteField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jbyte val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "B" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetByteField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setCharField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jchar val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "C" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetCharField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setDoubleField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jdouble val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "D" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetDoubleField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setFloatField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jfloat val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "F" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetFloatField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setIntField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jint val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "I" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetIntField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setLongField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jlong val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "J" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetLongField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setShortField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jshort val )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "S" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetShortField( env, obj, id, val );
+}
+
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectInputStream_setObjectField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jstring type_code,
+ jobject val )
+{
+ jfieldID id;
+ char * name_cstr;
+ char * type_cstr;
+
+ name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ return;
+
+ type_cstr = JCL_jstring_to_cstring( env, type_code );
+
+ if( type_cstr == NULL )
+ {
+ JCL_free_cstring( env, field_name, name_cstr );
+ return;
+ }
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, type_cstr );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+ JCL_free_cstring( env, type_code, type_cstr );
+
+ if( id == NULL )
+ return;
+
+ (*env)->SetObjectField( env, obj, id, val );
+}
diff --git a/native/jni/java-io/java_io_ObjectOutputStream.c b/native/jni/java-io/java_io_ObjectOutputStream.c
new file mode 100644
index 000000000..1c6d2c4be
--- /dev/null
+++ b/native/jni/java-io/java_io_ObjectOutputStream.c
@@ -0,0 +1,308 @@
+/* java_io_ObjectOutputStream.c -- Native methods for ObjectOutputStream
+ class
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+/* TODO: check exceptions */
+/* comments */
+
+#include <jni.h>
+#include <jcl.h>
+
+#include "java_io_ObjectOutputStream.h"
+
+#ifndef NDEBUG
+# define DEBUG( msg ) printf( msg );
+#else
+# define DEBUG( msg )
+#endif
+#define RETHROW_EXCEPTION( env ) if((*(env))->ExceptionOccurred((env)) != NULL) return;
+
+JNIEXPORT void JNICALL
+Java_java_io_ObjectOutputStream_callWriteMethod( JNIEnv * env,
+ jobject self,
+ jobject obj )
+{
+ jclass obj_class;
+ jmethodID id;
+
+ obj_class = (*env)->GetObjectClass( env, obj );
+ id = (*env)->GetMethodID( env, obj_class,
+ "writeObject",
+ "(Ljava/io/ObjectOutputStream;)V" );
+
+ if( id == NULL )
+ return;
+
+ (*env)->CallNonvirtualVoidMethod( env, obj, obj_class, id, self );
+}
+
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_ObjectOutputStream_getBooleanField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return JNI_FALSE;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "Z" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return JNI_FALSE;
+
+ return (*env)->GetBooleanField( env, obj, id );
+}
+
+
+JNIEXPORT jbyte JNICALL
+Java_java_io_ObjectOutputStream_getByteField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "B" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetByteField( env, obj, id );
+}
+
+
+JNIEXPORT jchar JNICALL
+Java_java_io_ObjectOutputStream_getCharField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "C" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetCharField( env, obj, id );
+}
+
+
+JNIEXPORT jdouble JNICALL
+Java_java_io_ObjectOutputStream_getDoubleField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "D" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetDoubleField( env, obj, id );
+}
+
+
+JNIEXPORT jfloat JNICALL
+Java_java_io_ObjectOutputStream_getFloatField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "F" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetFloatField( env, obj, id );
+}
+
+
+JNIEXPORT jint JNICALL
+Java_java_io_ObjectOutputStream_getIntField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "I" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetIntField( env, obj, id );
+}
+
+
+JNIEXPORT jlong JNICALL
+Java_java_io_ObjectOutputStream_getLongField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "J" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetLongField( env, obj, id );
+}
+
+
+JNIEXPORT jshort JNICALL
+Java_java_io_ObjectOutputStream_getShortField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name )
+{
+ jfieldID id;
+ char * name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, "S" );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return -1;
+
+ return (*env)->GetShortField( env, obj, id );
+}
+
+
+JNIEXPORT jobject JNICALL
+Java_java_io_ObjectOutputStream_getObjectField( JNIEnv * env,
+ jobject self,
+ jobject obj,
+ jstring field_name,
+ jstring type_code )
+{
+ jfieldID id;
+ char * name_cstr;
+ char * type_cstr;
+
+ name_cstr = JCL_jstring_to_cstring( env, field_name );
+
+ if( name_cstr == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return NULL;
+
+ type_cstr = JCL_jstring_to_cstring( env, type_code );
+
+ if( type_cstr == NULL )
+ {
+ JCL_free_cstring( env, field_name, name_cstr );
+ return NULL;
+ }
+
+ id = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, obj ),
+ name_cstr, type_cstr );
+
+ JCL_free_cstring( env, field_name, name_cstr );
+ JCL_free_cstring( env, type_code, type_cstr );
+
+ if( id == NULL )
+ /* Exception was thrown, so value is arbitrary */
+ return NULL;
+
+ return (*env)->GetObjectField( env, obj, id );
+}
diff --git a/native/jni/java-io/java_io_RandomAccessFile.c b/native/jni/java-io/java_io_RandomAccessFile.c
new file mode 100644
index 000000000..974a81f7c
--- /dev/null
+++ b/native/jni/java-io/java_io_RandomAccessFile.c
@@ -0,0 +1,180 @@
+/* RandomAccessFile.c - Native methods for java.io.RandomAccessFile
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <jni.h>
+#include <jcl.h>
+#include "java_io_RandomAccessFile.h"
+
+#include "javaio.h"
+
+/*************************************************************************/
+
+/*
+ * Returns the length of the file being read.
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_RandomAccessFile_lengthInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ return(_javaio_get_file_length(env, fd));
+}
+
+/*************************************************************************/
+
+/*
+ * Method to skip bytes in a file.
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_RandomAccessFile_skipInternal(JNIEnv *env, jobject obj, jint fd,
+ jint num_bytes)
+{
+ return(_javaio_skip_bytes(env, fd, num_bytes));
+}
+
+/*************************************************************************/
+
+/*
+ * Opens the file for reading
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_RandomAccessFile_open(JNIEnv *env, jobject obj, jstring name,
+ jboolean read_only)
+{
+ if (read_only)
+ return(_javaio_open(env, name, O_RDONLY));
+ else
+ return(_javaio_open(env, name, O_RDWR|O_CREAT));
+}
+
+/*************************************************************************/
+
+/*
+ * Closes the file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_RandomAccessFile_closeInternal(JNIEnv *env, jobject obj, jint fd)
+{
+ _javaio_close(env, fd);
+}
+
+/*************************************************************************/
+
+/*
+ * Reads bytes from the file
+ */
+
+JNIEXPORT jint JNICALL
+Java_java_io_RandomAccessFile_readInternal(JNIEnv *env, jobject obj, jint fd,
+ jarray buf, jint offset, jint len)
+{
+ return(_javaio_read(env, obj, fd, buf, offset, len));
+}
+
+/*************************************************************************/
+
+/*
+ * Write bytes to the file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_RandomAccessFile_writeInternal(JNIEnv *env, jobject obj, jint fd,
+ jarray buf, jint offset, jint len)
+{
+ _javaio_write(env, obj, fd, buf, offset, len);
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns the current position in the file
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_RandomAccessFile_getFilePointerInternal(JNIEnv *env, jobject obj,
+ jint fd)
+{
+ int rc = lseek(fd, 0, SEEK_CUR);
+ if (rc == -1)
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+
+ return(rc);
+}
+
+/*************************************************************************/
+
+/*
+ * This method seeks to the specified position from the beginning of the file
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_RandomAccessFile_seekInternal(JNIEnv *env, jobject obj,
+ jint fd, jlong pos)
+{
+ int rc = lseek(fd, pos, SEEK_SET);
+ if (rc == -1)
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+}
+
+/*************************************************************************/
+
+/*
+ * This method sets the length of the file. Hmm. Do all platforms have
+ * ftruncate? Probably not so we migth have to do some non-atomic stuff
+ * on those
+ */
+
+JNIEXPORT void JNICALL
+Java_java_io_RandomAccessFile_setLengthInternal(JNIEnv *env, jobject obj,
+ jint fd, jlong len)
+{
+ int rc;
+
+ jlong cur_len = _javaio_get_file_length(env, fd);
+ if (cur_len == -1)
+ return;
+
+ if (cur_len > len)
+ rc = ftruncate(fd, len);
+ else if (cur_len < len)
+ rc = lseek(fd, len - cur_len, SEEK_CUR);
+ else
+ return;
+
+ if (rc == -1)
+ JCL_ThrowException(env, "java/io/IOException", strerror(errno));
+}
+
diff --git a/native/jni/java-io/javaio.c b/native/jni/java-io/javaio.c
new file mode 100644
index 000000000..bc1db7290
--- /dev/null
+++ b/native/jni/java-io/javaio.c
@@ -0,0 +1,193 @@
+/* javaio.c - Common java.io native functions
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include <jni.h>
+
+#include "javaio.h"
+
+#include <malloc.h>
+
+/*
+ * Function to open a file
+ */
+
+jint
+_javaio_open(JNIEnv *env, jstring name, int flags)
+{
+ char *str_name;
+ int fd;
+
+ str_name = _javaio_jstring_to_cstring(env, name);
+ if (!str_name)
+ return(-1);
+
+ fd = open(str_name, flags, 0777);
+ (*env)->ReleaseStringUTFChars(env, name, str_name);
+ if (fd == -1)
+ {
+ if (errno == ENOENT)
+ _javaio_ThrowException(env, "java/io/FileNotFoundException",
+ strerror(errno));
+ else
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+ }
+
+ return(fd);
+}
+
+/*************************************************************************/
+
+/*
+ * Function to close a file
+ */
+
+void
+_javaio_close(JNIEnv *env, jint fd)
+{
+ int rc;
+
+ rc = close(fd);
+ if (rc == -1)
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+}
+
+/*************************************************************************/
+
+/*
+ * Skips bytes in a file
+ */
+
+jlong
+_javaio_skip_bytes(JNIEnv *env, jint fd, jlong num_bytes)
+{
+ int cur, new;
+
+ cur = lseek(fd, 0, SEEK_CUR);
+ if (cur == -1)
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+
+ new = lseek(fd, num_bytes, SEEK_CUR);
+ if (new == -1)
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+
+ return(new - cur);
+}
+
+/*************************************************************************/
+
+/*
+ * Gets the size of the file
+ */
+
+jlong
+_javaio_get_file_length(JNIEnv *env, jint fd)
+{
+ struct stat buf;
+ int rc;
+
+ rc = fstat(fd, &buf);
+ if (rc == -1)
+ {
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+ return(-1);
+ }
+
+ return(buf.st_size);
+}
+
+/*************************************************************************/
+
+/*
+ * Reads data from a file
+ */
+
+jint
+_javaio_read(JNIEnv *env, jobject obj, jint fd, jarray buf, jint offset,
+ jint len)
+{
+ jbyte *bufptr;
+ int rc;
+
+ bufptr = (*env)->GetByteArrayElements(env, buf, JNI_FALSE);
+ if (!bufptr)
+ {
+ _javaio_ThrowException(env, "java/io/IOException", "Internal Error");
+ return(-1);
+ }
+
+ rc = read(fd, (bufptr + offset), len);
+ if (rc == -1)
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+
+ (*env)->ReleaseByteArrayElements(env, buf, bufptr, 0);
+
+ if (rc == 0)
+ rc = -1;
+
+ return(rc);
+}
+
+/*************************************************************************/
+
+/*
+ * Writes data to a file
+ */
+
+jint
+_javaio_write(JNIEnv *env, jobject obj, jint fd, jarray buf, jint offset,
+ jint len)
+{
+ jbyte *bufptr;
+ int rc;
+
+ bufptr = (*env)->GetByteArrayElements(env, buf, 0);
+ if (!bufptr)
+ {
+ _javaio_ThrowException(env, "java/io/IOException", "Internal Error");
+ return(-1);
+ }
+
+ rc = write(fd, (bufptr + offset), len);
+ if (rc == -1)
+ _javaio_ThrowException(env, "java/io/IOException", strerror(errno));
+
+ (*env)->ReleaseByteArrayElements(env, buf, bufptr, 0);
+
+ if (rc == 0)
+ rc = -1;
+
+ return(rc);
+}
+
diff --git a/native/jni/java-io/javaio.h b/native/jni/java-io/javaio.h
new file mode 100644
index 000000000..20deaf13c
--- /dev/null
+++ b/native/jni/java-io/javaio.h
@@ -0,0 +1,45 @@
+/* javaio.h - Declaration for common java.io native functions
+ Copyright (C) 1998 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
+#ifndef JAVAIO_H_INCLUDED
+#define JAVAIO_H_INCLUDED
+
+#include <stddef.h>
+
+/*
+ * Function Prototypes
+ */
+
+extern jlong _javaio_get_file_length(JNIEnv *, jint);
+extern jlong _javaio_skip_bytes(JNIEnv *, jint, jlong);
+extern jint _javaio_open(JNIEnv *, jstring, int);
+extern void _javaio_close(JNIEnv *, jint fd);
+extern jint _javaio_read(JNIEnv *, jobject obj, jint, jarray, jint, jint);
+extern jint _javaio_write(JNIEnv *, jobject obj, jint, jarray, jint, jint);
+
+#endif /* JAVAIO_H_INCLUDED */
+