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>
29 #include <gnu/java/nio/MappedByteBufferImpl.h>
30 #include <java/nio/channels/FileChannel.h>
31 #include <java/nio/channels/FileLock.h>
32 #include <gnu/java/nio/channels/FileChannelImpl.h>
34 using gnu::gcj::RawData
;
35 using java::io::IOException
;
36 using gnu::java::nio::MappedByteBufferImpl
;
37 using java::io::InterruptedIOException
;
38 using java::io::FileNotFoundException
;
39 using java::lang::ArrayIndexOutOfBoundsException
;
40 using java::lang::NullPointerException
;
41 using gnu::java::nio::channels::FileChannelImpl
;
43 extern "C" void diag_write_char (char c
);
46 diag_write (char *data
, int len
)
50 diag_write_char (*data
++);
55 #define NO_FSYNC_MESSAGE "sync unsupported"
58 FileChannelImpl::init(void)
60 in
= new FileChannelImpl((jint
) 0, FileChannelImpl::READ
);
61 out
= new FileChannelImpl((jint
) 1, FileChannelImpl::WRITE
);
62 err
= new FileChannelImpl((jint
) 2, FileChannelImpl::WRITE
);
67 FileChannelImpl::valid (void)
73 FileChannelImpl::sync (void)
75 // Some files don't support fsync. We don't bother reporting these
79 throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE
));
85 FileChannelImpl::open (jstring
, jint
)
91 FileChannelImpl::write (jint
)
98 FileChannelImpl::write (jbyteArray b
, jint offset
, jint len
)
101 throw new NullPointerException
;
102 if (offset
< 0 || len
< 0 || offset
+ len
> JvGetArrayLength (b
))
103 throw new ArrayIndexOutOfBoundsException
;
104 char *bytes
= (char *)elements (b
) + offset
;
105 ::diag_write (bytes
, len
);
109 FileChannelImpl::implCloseChannel (void)
114 FileChannelImpl::implTruncate (jlong
)
119 FileChannelImpl::seek (jlong
)
124 FileChannelImpl::size (void)
130 FileChannelImpl::implPosition (void)
136 FileChannelImpl::read (void)
142 FileChannelImpl::read (jbyteArray buffer
, jint offset
, jint count
)
148 FileChannelImpl::available (void)
154 FileChannelImpl::lock (jlong
, jlong
, jboolean
, jboolean
)
156 throw new IOException (JvNewStringLatin1
157 ("gnu.java.nio.FileChannelImpl.lock() not implemented"));
161 FileChannelImpl::unlock (jlong
, jlong
)
163 throw new IOException (JvNewStringLatin1
164 ("gnu.java.nio.channels.FileChannelImpl.unlock() not implemented"));
167 java::nio::MappedByteBuffer
*
168 FileChannelImpl::mapImpl (jchar
, jlong
, jint
)
174 MappedByteBufferImpl::unmapImpl ()
179 MappedByteBufferImpl::loadImpl ()
184 MappedByteBufferImpl::isLoadedImpl ()
190 MappedByteBufferImpl::forceImpl ()