| 1 | // natFileDescriptor.cc - Native part of FileDescriptor class.
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
|
|---|
| 4 |
|
|---|
| 5 | This file is part of libgcj.
|
|---|
| 6 |
|
|---|
| 7 | This software is copyrighted work licensed under the terms of the
|
|---|
| 8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|---|
| 9 | details. */
|
|---|
| 10 |
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 |
|
|---|
| 13 | #include <errno.h>
|
|---|
| 14 | #include <string.h>
|
|---|
| 15 | #include <sys/types.h>
|
|---|
| 16 | #include <sys/stat.h>
|
|---|
| 17 | #include <sys/param.h>
|
|---|
| 18 |
|
|---|
| 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 |
|
|---|
| 30 | extern "C" void diag_write_char (char c);
|
|---|
| 31 |
|
|---|
| 32 | static void
|
|---|
| 33 | diag_write (char *data, int len)
|
|---|
| 34 | {
|
|---|
| 35 | while (len > 0)
|
|---|
| 36 | {
|
|---|
| 37 | diag_write_char (*data++);
|
|---|
| 38 | len--;
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | #define NO_FSYNC_MESSAGE "sync unsupported"
|
|---|
| 43 |
|
|---|
| 44 | void
|
|---|
| 45 | java::io::FileDescriptor::init(void)
|
|---|
| 46 | {
|
|---|
| 47 | in = new java::io::FileDescriptor(0);
|
|---|
| 48 | out = new java::io::FileDescriptor(1);
|
|---|
| 49 | err = new java::io::FileDescriptor(2);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | jboolean
|
|---|
| 53 | java::io::FileDescriptor::valid (void)
|
|---|
| 54 | {
|
|---|
| 55 | return true;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void
|
|---|
| 59 | java::io::FileDescriptor::sync (void)
|
|---|
| 60 | {
|
|---|
| 61 | // Some files don't support fsync. We don't bother reporting these
|
|---|
| 62 | // as errors.
|
|---|
| 63 | #ifdef HAVE_FSYNC
|
|---|
| 64 | #else
|
|---|
| 65 | throw new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE));
|
|---|
| 66 | #endif
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | jint
|
|---|
| 70 | java::io::FileDescriptor::open (jstring path, jint jflags)
|
|---|
| 71 | {
|
|---|
| 72 | return fd;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | void
|
|---|
| 76 | java::io::FileDescriptor::write (jint b)
|
|---|
| 77 | {
|
|---|
| 78 | char d = (char) b;
|
|---|
| 79 | ::diag_write (&d, 1);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void
|
|---|
| 83 | java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len)
|
|---|
| 84 | {
|
|---|
| 85 | if (! b)
|
|---|
| 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);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void
|
|---|
| 94 | java::io::FileDescriptor::close (void)
|
|---|
| 95 | {
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | jint
|
|---|
| 99 | java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
|
|---|
| 100 | {
|
|---|
| 101 | JvAssert (whence == SET || whence == CUR);
|
|---|
| 102 | return 0;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | jlong
|
|---|
| 106 | java::io::FileDescriptor::length (void)
|
|---|
| 107 | {
|
|---|
| 108 | return 0;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | jlong
|
|---|
| 112 | java::io::FileDescriptor::getFilePointer (void)
|
|---|
| 113 | {
|
|---|
| 114 | return 0;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | jint
|
|---|
| 118 | java::io::FileDescriptor::read (void)
|
|---|
| 119 | {
|
|---|
| 120 | return 0;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | jint
|
|---|
| 124 | java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
|
|---|
| 125 | {
|
|---|
| 126 | return 0;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | jint
|
|---|
| 130 | java::io::FileDescriptor::available (void)
|
|---|
| 131 | {
|
|---|
| 132 | return 0;
|
|---|
| 133 | }
|
|---|