1 // natFileDescriptor.cc - Native part of FileDescriptor class.
3 /* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation
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::init(void)
47 in
= new java::io::FileDescriptor(0);
48 out
= new java::io::FileDescriptor(1);
49 err
= new java::io::FileDescriptor(2);
53 java::io::FileDescriptor::valid (void)
59 java::io::FileDescriptor::sync (void)
61 // Some files don't support fsync. We don't bother reporting these
65 throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE
));
70 java::io::FileDescriptor::open (jstring path
, jint jflags
)
76 java::io::FileDescriptor::write (jint b
)
83 java::io::FileDescriptor::write (jbyteArray b
, jint offset
, jint len
)
86 throw new java::lang::NullPointerException
;
87 if (offset
< 0 || len
< 0 || offset
+ len
> JvGetArrayLength (b
))
88 throw new java::lang::ArrayIndexOutOfBoundsException
;
89 char *bytes
= (char *)elements (b
) + offset
;
90 ::diag_write (bytes
, len
);
94 java::io::FileDescriptor::close (void)
99 java::io::FileDescriptor::setLength (long)
104 java::io::FileDescriptor::seek (jlong pos
, jint whence
, jboolean
)
106 JvAssert (whence
== SET
|| whence
== CUR
);
111 java::io::FileDescriptor::getLength (void)
117 java::io::FileDescriptor::getFilePointer (void)
123 java::io::FileDescriptor::read (void)
129 java::io::FileDescriptor::read (jbyteArray buffer
, jint offset
, jint count
)
135 java::io::FileDescriptor::available (void)