summaryrefslogtreecommitdiff
path: root/libjava/gnu/java/nio/channels/natFileChannelEcos.cc
blob: 78575e7e66a791241048f378d39f68ecc91b1819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// natFileDescriptor.cc - Native part of FileDescriptor class.

/* Copyright (C) 1998, 1999, 2001, 2002  Free Software Foundation

   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>

#include <gcj/cni.h>
#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>
#include <gnu/java/nio/MappedByteBufferImpl.h>
#include <java/nio/channels/FileChannel.h>
#include <java/nio/channels/FileLock.h>
#include <gnu/java/nio/channels/FileChannelImpl.h>

using gnu::gcj::RawData;
using java::io::IOException;
using gnu::java::nio::MappedByteBufferImpl;
using java::io::InterruptedIOException;
using java::io::FileNotFoundException;
using java::lang::ArrayIndexOutOfBoundsException;
using java::lang::NullPointerException;
using gnu::java::nio::channels::FileChannelImpl;

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"

void
FileChannelImpl::init(void)
{
  in = new FileChannelImpl((jint) 0, FileChannelImpl::READ);
  out = new FileChannelImpl((jint) 1, FileChannelImpl::WRITE);
  err = new FileChannelImpl((jint) 2, FileChannelImpl::WRITE);
}

#if 0
jboolean
FileChannelImpl::valid (void)
{
  return true;
}

void
FileChannelImpl::sync (void)
{
  // Some files don't support fsync.  We don't bother reporting these
  // as errors.
#ifdef HAVE_FSYNC
#else
  throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE));
#endif
}
#endif

jint
FileChannelImpl::open (jstring, jint)
{
  return fd;
}

void
FileChannelImpl::write (jint)
{
  char d = (char) b;
  ::diag_write (&d, 1);
}

void
FileChannelImpl::write (jbyteArray b, jint offset, jint len)
{
  if (! b)
    throw new NullPointerException;
  if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
    throw new ArrayIndexOutOfBoundsException;
  char *bytes = (char *)elements (b) + offset;
  ::diag_write (bytes, len);
}

void
FileChannelImpl::implCloseChannel (void)
{
}

void
FileChannelImpl::implTruncate (jlong)
{
}

void
FileChannelImpl::seek (jlong)
{
}

jlong
FileChannelImpl::size (void)
{
  return 0;
}

jlong
FileChannelImpl::implPosition (void)
{
  return 0;
}

jint
FileChannelImpl::read (void)
{
  return 0;
}

jint
FileChannelImpl::read (jbyteArray buffer, jint offset, jint count)
{
  return 0;
}

jint
FileChannelImpl::available (void)
{
  return 0;
}

jboolean
FileChannelImpl::lock (jlong, jlong, jboolean, jboolean)
{
  throw new IOException (JvNewStringLatin1
    ("gnu.java.nio.FileChannelImpl.lock() not implemented"));
}

void
FileChannelImpl::unlock (jlong, jlong)
{
  throw new IOException (JvNewStringLatin1
    ("gnu.java.nio.channels.FileChannelImpl.unlock() not implemented"));
}

java::nio::MappedByteBuffer *
FileChannelImpl::mapImpl (jchar, jlong, jint)
{
  return NULL;
}

void
MappedByteBufferImpl::unmapImpl ()
{
}

void
MappedByteBufferImpl::loadImpl ()
{
}

jboolean
MappedByteBufferImpl::isLoadedImpl ()
{
  return true;
}

void
MappedByteBufferImpl::forceImpl ()
{
}