/[classpath]/classpath/native/jni/java-io/FileDescriptor.c
ViewVC logotype

Diff of /classpath/native/jni/java-io/FileDescriptor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by arenn, Mon Mar 10 00:22:27 2003 UTC revision 1.5 by arenn, Sat Mar 15 21:37:45 2003 UTC
# Line 87  exception statement from your version. * Line 87  exception statement from your version. *
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;
# Line 186  Java_java_io_FileDescriptor_nativeClose( Line 189  Java_java_io_FileDescriptor_nativeClose(
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;
# Line 196  Java_java_io_FileDescriptor_nativeWriteB Line 199  Java_java_io_FileDescriptor_nativeWriteB
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)
# Line 205  Java_java_io_FileDescriptor_nativeWriteB Line 208  Java_java_io_FileDescriptor_nativeWriteB
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  /*************************************************************************/  /*************************************************************************/
# Line 217  Java_java_io_FileDescriptor_nativeWriteB Line 220  Java_java_io_FileDescriptor_nativeWriteB
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;
# Line 256  Java_java_io_FileDescriptor_nativeWriteB Line 259  Java_java_io_FileDescriptor_nativeWriteB
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;
# Line 276  Java_java_io_FileDescriptor_nativeReadBy Line 279  Java_java_io_FileDescriptor_nativeReadBy
279            return(-1);            return(-1);
280          }          }
281      }      }
282    return(b);    return(b & 0xFF);
283  }  }
284    
285  /*************************************************************************/  /*************************************************************************/
# Line 284  Java_java_io_FileDescriptor_nativeReadBy Line 287  Java_java_io_FileDescriptor_nativeReadBy
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;
# Line 312  Java_java_io_FileDescriptor_nativeReadBu Line 315  Java_java_io_FileDescriptor_nativeReadBu
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))
# Line 325  Java_java_io_FileDescriptor_nativeReadBu Line 328  Java_java_io_FileDescriptor_nativeReadBu
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  /*************************************************************************/  /*************************************************************************/
# Line 333  Java_java_io_FileDescriptor_nativeReadBu Line 336  Java_java_io_FileDescriptor_nativeReadBu
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)
# Line 400  Java_java_io_FileDescriptor_nativeAvaila Line 403  Java_java_io_FileDescriptor_nativeAvaila
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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26