1999-04-07 16:42:40 +02:00
|
|
|
// natFileDescriptor.cc - Native part of FileDescriptor class.
|
|
|
|
|
2002-03-07 00:23:34 +01:00
|
|
|
/* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
1999-09-11 00:03:10 +02:00
|
|
|
#include <gcj/cni.h>
|
1999-04-07 16:42:40 +02:00
|
|
|
#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"
|
|
|
|
|
2002-03-06 23:37:26 +01:00
|
|
|
void
|
|
|
|
java::io::FileDescriptor::init(void)
|
|
|
|
{
|
2002-03-07 00:23:34 +01:00
|
|
|
in = new java::io::FileDescriptor(0);
|
|
|
|
out = new java::io::FileDescriptor(1);
|
|
|
|
err = new java::io::FileDescriptor(2);
|
2002-03-06 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
1999-04-07 16:42:40 +02:00
|
|
|
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
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE));
|
1999-04-07 16:42:40 +02:00
|
|
|
#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)
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
throw new java::lang::NullPointerException;
|
1999-04-07 16:42:40 +02:00
|
|
|
if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
throw new java::lang::ArrayIndexOutOfBoundsException;
|
1999-04-07 16:42:40 +02:00
|
|
|
char *bytes = (char *)elements (b) + offset;
|
|
|
|
::diag_write (bytes, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
java::io::FileDescriptor::close (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-24 19:48:41 +02:00
|
|
|
void
|
|
|
|
java::io::FileDescriptor::setLength (long)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-04-07 16:42:40 +02:00
|
|
|
jint
|
2001-08-03 01:46:39 +02:00
|
|
|
java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
JvAssert (whence == SET || whence == CUR);
|
|
|
|
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;
|
|
|
|
}
|