1 // natFileDescriptor.cc - Native part of FileDescriptor class.
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
15 #include <sys/types.h>
17 #include <sys/param.h>
21 #include <java/io/FileDescriptor.h>
22 #include <java/io/SyncFailedException.h>
23 #include <java/io/IOException.h>
24 #include <java/io/EOFException.h>
25 #include <java/lang/ArrayIndexOutOfBoundsException.h>
26 #include <java/lang/NullPointerException.h>
27 #include <java/lang/String.h>
28 #include <java/io/FileNotFoundException.h>
30 extern "C" void diag_write_char (char c);
33 diag_write (char *data, int len)
37 diag_write_char (*data++);
42 #define NO_FSYNC_MESSAGE "sync unsupported"
45 java::io::FileDescriptor::valid (void)
51 java::io::FileDescriptor::sync (void)
53 // Some files don't support fsync. We don't bother reporting these
57 JvThrow (new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE)));
62 java::io::FileDescriptor::open (jstring path, jint jflags)
68 java::io::FileDescriptor::write (jint b)
75 java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len)
78 JvThrow (new java::lang::NullPointerException);
79 if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
80 JvThrow (new java::lang::ArrayIndexOutOfBoundsException);
81 char *bytes = (char *)elements (b) + offset;
82 ::diag_write (bytes, len);
86 java::io::FileDescriptor::close (void)
91 java::io::FileDescriptor::seek (jlong pos, jint whence)
93 JvAssert (whence == SET || whence == CUR);
95 jlong len = length ();
96 jlong here = getFilePointer ();
98 if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
99 JvThrow (new EOFException);
105 java::io::FileDescriptor::length (void)
111 java::io::FileDescriptor::getFilePointer (void)
117 java::io::FileDescriptor::read (void)
123 java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
129 java::io::FileDescriptor::available (void)