OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / libjava / java / io / natFileDescriptorEcos.cc
1 // natFileDescriptor.cc - Native part of FileDescriptor class.
2
3 /* Copyright (C) 1998, 1999  Cygnus Solutions
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 <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 jboolean
45 java::io::FileDescriptor::valid (void)
46 {
47   return true;
48 }
49
50 void
51 java::io::FileDescriptor::sync (void)
52 {
53   // Some files don't support fsync.  We don't bother reporting these
54   // as errors.
55 #ifdef HAVE_FSYNC
56 #else
57   JvThrow (new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE)));
58 #endif
59 }
60
61 jint
62 java::io::FileDescriptor::open (jstring path, jint jflags)
63 {
64   return fd;
65 }
66
67 void
68 java::io::FileDescriptor::write (jint b)
69 {
70   char d = (char) b;
71   ::diag_write (&d, 1);
72 }
73
74 void
75 java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len)
76 {
77   if (! b)
78     JvThrow (new java::lang::NullPointerException);
79   if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
80     JvThrow (new java::lang::ArrayIndexOutOfBoundsException);
81   char *bytes = (char *)elements (b) + offset;
82   ::diag_write (bytes, len);
83 }
84
85 void
86 java::io::FileDescriptor::close (void)
87 {
88 }
89
90 jint
91 java::io::FileDescriptor::seek (jlong pos, jint whence)
92 {
93   JvAssert (whence == SET || whence == CUR);
94
95   jlong len = length ();
96   jlong here = getFilePointer ();
97
98   if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
99     JvThrow (new EOFException);
100
101   return 0;
102 }
103
104 jlong
105 java::io::FileDescriptor::length (void)
106 {
107   return 0;
108 }
109
110 jlong
111 java::io::FileDescriptor::getFilePointer (void)
112 {
113   return 0;
114 }
115
116 jint
117 java::io::FileDescriptor::read (void)
118 {
119   return 0;
120 }
121
122 jint
123 java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
124 {
125   return 0;
126 }
127
128 jint
129 java::io::FileDescriptor::available (void)
130 {
131   return 0;
132 }