Reset branch to trunk.
[official-gcc.git] / trunk / libjava / gnu / java / nio / channels / natFileChannelEcos.cc
blob78575e7e66a791241048f378d39f68ecc91b1819
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
9 details. */
11 #include <config.h>
13 #include <errno.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/param.h>
19 #include <gcj/cni.h>
20 #include <jvm.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);
45 static void
46 diag_write (char *data, int len)
48 while (len > 0)
50 diag_write_char (*data++);
51 len--;
55 #define NO_FSYNC_MESSAGE "sync unsupported"
57 void
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);
65 #if 0
66 jboolean
67 FileChannelImpl::valid (void)
69 return true;
72 void
73 FileChannelImpl::sync (void)
75 // Some files don't support fsync. We don't bother reporting these
76 // as errors.
77 #ifdef HAVE_FSYNC
78 #else
79 throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE));
80 #endif
82 #endif
84 jint
85 FileChannelImpl::open (jstring, jint)
87 return fd;
90 void
91 FileChannelImpl::write (jint)
93 char d = (char) b;
94 ::diag_write (&d, 1);
97 void
98 FileChannelImpl::write (jbyteArray b, jint offset, jint len)
100 if (! b)
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);
108 void
109 FileChannelImpl::implCloseChannel (void)
113 void
114 FileChannelImpl::implTruncate (jlong)
118 void
119 FileChannelImpl::seek (jlong)
123 jlong
124 FileChannelImpl::size (void)
126 return 0;
129 jlong
130 FileChannelImpl::implPosition (void)
132 return 0;
135 jint
136 FileChannelImpl::read (void)
138 return 0;
141 jint
142 FileChannelImpl::read (jbyteArray buffer, jint offset, jint count)
144 return 0;
147 jint
148 FileChannelImpl::available (void)
150 return 0;
153 jboolean
154 FileChannelImpl::lock (jlong, jlong, jboolean, jboolean)
156 throw new IOException (JvNewStringLatin1
157 ("gnu.java.nio.FileChannelImpl.lock() not implemented"));
160 void
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)
170 return NULL;
173 void
174 MappedByteBufferImpl::unmapImpl ()
178 void
179 MappedByteBufferImpl::loadImpl ()
183 jboolean
184 MappedByteBufferImpl::isLoadedImpl ()
186 return true;
189 void
190 MappedByteBufferImpl::forceImpl ()