87 |
// FIXME: This can't be right. Need converter macros |
// FIXME: This can't be right. Need converter macros |
88 |
#define CONVERT_JLONG_TO_OFF_T(x) (x) |
#define CONVERT_JLONG_TO_OFF_T(x) (x) |
89 |
|
|
90 |
|
// FIXME: This can't be right. Need converter macros |
91 |
|
#define CONVERT_JINT_TO_INT(x) ((int)(x & 0xFFFF)) |
92 |
|
|
93 |
/* These are initialized in nativeInit() */ |
/* These are initialized in nativeInit() */ |
94 |
static jint SET; |
static jint SET; |
95 |
static jint CUR; |
static jint CUR; |
189 |
* Writes a single byte to the specified file descriptor |
* Writes a single byte to the specified file descriptor |
190 |
* Return status code, exception on error |
* Return status code, exception on error |
191 |
*/ |
*/ |
192 |
JNIEXPORT jlong JNICALL |
JNIEXPORT jint JNICALL |
193 |
Java_java_io_FileDescriptor_nativeWriteByte(JNIEnv *env, jobject obj, |
Java_java_io_FileDescriptor_nativeWriteByte(JNIEnv *env, jobject obj, |
194 |
jlong fd, jlong b) |
jlong fd, jint b) |
195 |
{ |
{ |
196 |
int native_fd; |
int native_fd; |
197 |
int native_byte; |
int native_byte; |
199 |
ssize_t rc; |
ssize_t rc; |
200 |
|
|
201 |
native_fd = CONVERT_JLONG_TO_INT(fd); |
native_fd = CONVERT_JLONG_TO_INT(fd); |
202 |
native_byte = CONVERT_JLONG_TO_INT(b); |
native_byte = CONVERT_JINT_TO_INT(b); |
203 |
buf[0] = (char)(native_byte & 0xFF); |
buf[0] = (char)(native_byte & 0xFF); |
204 |
|
|
205 |
while (rc != 1) |
while (rc != 1) |
208 |
if ((rc == -1) && (errno != EINTR)) |
if ((rc == -1) && (errno != EINTR)) |
209 |
{ |
{ |
210 |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
211 |
return(rc); |
return(-1); |
212 |
} |
} |
213 |
} |
} |
214 |
|
|
215 |
return(rc); |
return(0); |
216 |
} |
} |
217 |
|
|
218 |
/*************************************************************************/ |
/*************************************************************************/ |
220 |
* Writes a byte buffer to the specified file descriptor |
* Writes a byte buffer to the specified file descriptor |
221 |
* Return status code, exception on error |
* Return status code, exception on error |
222 |
*/ |
*/ |
223 |
JNIEXPORT jlong JNICALL |
JNIEXPORT jint JNICALL |
224 |
Java_java_io_FileDescriptor_nativeWriteBuf(JNIEnv *env, jobject obj, |
Java_java_io_FileDescriptor_nativeWriteBuf(JNIEnv *env, jobject obj, |
225 |
jlong fd, jarray buf, jlong offset, |
jlong fd, jarray buf, jint offset, |
226 |
jlong len) |
jint len) |
227 |
{ |
{ |
228 |
int native_fd; |
int native_fd; |
229 |
ssize_t rc, bytes_written = 0; |
ssize_t rc, bytes_written = 0; |
259 |
* Read a single byte from the file descriptor |
* Read a single byte from the file descriptor |
260 |
* Return byte read or -1 on eof, exception on error |
* Return byte read or -1 on eof, exception on error |
261 |
*/ |
*/ |
262 |
JNIEXPORT jlong JNICALL |
JNIEXPORT jint JNICALL |
263 |
Java_java_io_FileDescriptor_nativeReadByte(JNIEnv *env, jobject obj, jlong fd) |
Java_java_io_FileDescriptor_nativeReadByte(JNIEnv *env, jobject obj, jlong fd) |
264 |
{ |
{ |
265 |
int native_fd; |
int native_fd; |
279 |
return(-1); |
return(-1); |
280 |
} |
} |
281 |
} |
} |
282 |
return(b); |
return(b & 0xFF); |
283 |
} |
} |
284 |
|
|
285 |
/*************************************************************************/ |
/*************************************************************************/ |
287 |
* Reads to a byte buffer from the specified file descriptor |
* Reads to a byte buffer from the specified file descriptor |
288 |
* Return number of bytes read or -1 on eof, exception on error |
* Return number of bytes read or -1 on eof, exception on error |
289 |
*/ |
*/ |
290 |
JNIEXPORT jlong JNICALL |
JNIEXPORT jint JNICALL |
291 |
Java_java_io_FileDescriptor_nativeReadBuf(JNIEnv *env, jobject obj, |
Java_java_io_FileDescriptor_nativeReadBuf(JNIEnv *env, jobject obj, |
292 |
jlong fd, jarray buf, jlong offset, |
jlong fd, jarray buf, jint offset, |
293 |
jlong len) |
jint len) |
294 |
{ |
{ |
295 |
int native_fd; |
int native_fd; |
296 |
ssize_t rc, bytes_read = 0; |
ssize_t rc, bytes_read = 0; |
315 |
if (bytes_read == 0) |
if (bytes_read == 0) |
316 |
return(-1); /* Signal end of file to Java */ |
return(-1); /* Signal end of file to Java */ |
317 |
else |
else |
318 |
return(bytes_read); |
return((jint)(bytes_read & 0xFFFF)); |
319 |
} |
} |
320 |
|
|
321 |
if ((rc == -1) && (errno != EINTR)) |
if ((rc == -1) && (errno != EINTR)) |
328 |
} |
} |
329 |
|
|
330 |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
331 |
return(bytes_read); |
return((jint)(bytes_read & 0xFFFF)); |
332 |
} |
} |
333 |
|
|
334 |
/*************************************************************************/ |
/*************************************************************************/ |
336 |
* Return number of bytes that can be read from the file w/o blocking. |
* Return number of bytes that can be read from the file w/o blocking. |
337 |
* Exception on error |
* Exception on error |
338 |
*/ |
*/ |
339 |
JNIEXPORT jlong JNICALL |
JNIEXPORT jint JNICALL |
340 |
Java_java_io_FileDescriptor_nativeAvailable(JNIEnv *env, jobject obj, jlong fd) |
Java_java_io_FileDescriptor_nativeAvailable(JNIEnv *env, jobject obj, jlong fd) |
341 |
{ |
{ |
342 |
#if defined(FIONREAD) || defined(HAVE_SELECT) || defined(HAVE_FSTAT) |
#if defined(FIONREAD) || defined(HAVE_SELECT) || defined(HAVE_FSTAT) |
403 |
if (!found) |
if (!found) |
404 |
return(0); |
return(0); |
405 |
else |
else |
406 |
return(num); |
return((jint)(num & 0xFFFF)); |
407 |
|
|
408 |
#else /* defined FIONREAD, HAVE_SELECT, HAVE_FSTAT */ |
#else /* defined FIONREAD, HAVE_SELECT, HAVE_FSTAT */ |
409 |
/* FIXME: Probably operation isn't supported, but this exception |
/* FIXME: Probably operation isn't supported, but this exception |