summaryrefslogtreecommitdiff
path: root/libjava/java/io/natFileDescriptorEcos.cc
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>1999-04-07 14:42:40 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>1999-04-07 14:42:40 +0000
commit2c60951ba0efef23e2b765964b5dc0f1f49438a9 (patch)
treed96801a16fdf03a5682ef98730fe333a46eef944 /libjava/java/io/natFileDescriptorEcos.cc
parent1135eed2207f8f82c589e42ce113a1c2f0310778 (diff)
downloadgcc-2c60951ba0efef23e2b765964b5dc0f1f49438a9.tar.gz
Initial revision
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26263 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io/natFileDescriptorEcos.cc')
-rw-r--r--libjava/java/io/natFileDescriptorEcos.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/libjava/java/io/natFileDescriptorEcos.cc b/libjava/java/io/natFileDescriptorEcos.cc
new file mode 100644
index 00000000000..f2c3fb0db79
--- /dev/null
+++ b/libjava/java/io/natFileDescriptorEcos.cc
@@ -0,0 +1,132 @@
+// natFileDescriptor.cc - Native part of FileDescriptor class.
+
+/* Copyright (C) 1998, 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#include <cni.h>
+#include <jvm.h>
+#include <java/io/FileDescriptor.h>
+#include <java/io/SyncFailedException.h>
+#include <java/io/IOException.h>
+#include <java/io/EOFException.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
+#include <java/lang/NullPointerException.h>
+#include <java/lang/String.h>
+#include <java/io/FileNotFoundException.h>
+
+extern "C" void diag_write_char (char c);
+
+static void
+diag_write (char *data, int len)
+{
+ while (len > 0)
+ {
+ diag_write_char (*data++);
+ len--;
+ }
+}
+
+#define NO_FSYNC_MESSAGE "sync unsupported"
+
+jboolean
+java::io::FileDescriptor::valid (void)
+{
+ return true;
+}
+
+void
+java::io::FileDescriptor::sync (void)
+{
+ // Some files don't support fsync. We don't bother reporting these
+ // as errors.
+#ifdef HAVE_FSYNC
+#else
+ JvThrow (new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE)));
+#endif
+}
+
+jint
+java::io::FileDescriptor::open (jstring path, jint jflags)
+{
+ return fd;
+}
+
+void
+java::io::FileDescriptor::write (jint b)
+{
+ char d = (char) b;
+ ::diag_write (&d, 1);
+}
+
+void
+java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len)
+{
+ if (! b)
+ JvThrow (new java::lang::NullPointerException);
+ if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
+ JvThrow (new java::lang::ArrayIndexOutOfBoundsException);
+ char *bytes = (char *)elements (b) + offset;
+ ::diag_write (bytes, len);
+}
+
+void
+java::io::FileDescriptor::close (void)
+{
+}
+
+jint
+java::io::FileDescriptor::seek (jlong pos, jint whence)
+{
+ JvAssert (whence == SET || whence == CUR);
+
+ jlong len = length ();
+ jlong here = getFilePointer ();
+
+ if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
+ JvThrow (new EOFException);
+
+ return 0;
+}
+
+jlong
+java::io::FileDescriptor::length (void)
+{
+ return 0;
+}
+
+jlong
+java::io::FileDescriptor::getFilePointer (void)
+{
+ return 0;
+}
+
+jint
+java::io::FileDescriptor::read (void)
+{
+ return 0;
+}
+
+jint
+java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
+{
+ return 0;
+}
+
+jint
+java::io::FileDescriptor::available (void)
+{
+ return 0;
+}