src/share/native/java/io/RandomAccessFile.c

Print this page


   1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 106     FD fd;
 107     jlong cur = jlong_zero;
 108     jlong end = jlong_zero;
 109 
 110     fd = GET_FD(this, raf_fd);
 111     if (fd == -1) {
 112         JNU_ThrowIOException(env, "Stream Closed");
 113         return -1;
 114     }
 115     if ((cur = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
 116         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 117     } else if ((end = IO_Lseek(fd, 0L, SEEK_END)) == -1) {
 118         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 119     } else if (IO_Lseek(fd, cur, SEEK_SET) == -1) {
 120         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 121     }
 122     return end;
 123 }
 124 
 125 JNIEXPORT void JNICALL
 126 Java_java_io_RandomAccessFile_seek(JNIEnv *env,
 127                     jobject this, jlong pos) {
 128 
 129     FD fd;
 130 
 131     fd = GET_FD(this, raf_fd);
 132     if (fd == -1) {
 133         JNU_ThrowIOException(env, "Stream Closed");
 134         return;
 135     }
 136     if (pos < jlong_zero) {
 137         JNU_ThrowIOException(env, "Negative seek offset");
 138     } else if (IO_Lseek(fd, pos, SEEK_SET) == -1) {
 139         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 140     }
 141 }
 142 
 143 JNIEXPORT void JNICALL
 144 Java_java_io_RandomAccessFile_setLength(JNIEnv *env, jobject this,
 145                                         jlong newLength)
 146 {
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 106     FD fd;
 107     jlong cur = jlong_zero;
 108     jlong end = jlong_zero;
 109 
 110     fd = GET_FD(this, raf_fd);
 111     if (fd == -1) {
 112         JNU_ThrowIOException(env, "Stream Closed");
 113         return -1;
 114     }
 115     if ((cur = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
 116         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 117     } else if ((end = IO_Lseek(fd, 0L, SEEK_END)) == -1) {
 118         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 119     } else if (IO_Lseek(fd, cur, SEEK_SET) == -1) {
 120         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 121     }
 122     return end;
 123 }
 124 
 125 JNIEXPORT void JNICALL
 126 Java_java_io_RandomAccessFile_seek0(JNIEnv *env,
 127                     jobject this, jlong pos) {
 128 
 129     FD fd;
 130 
 131     fd = GET_FD(this, raf_fd);
 132     if (fd == -1) {
 133         JNU_ThrowIOException(env, "Stream Closed");
 134         return;
 135     }
 136     if (pos < jlong_zero) {
 137         JNU_ThrowIOException(env, "Negative seek offset");
 138     } else if (IO_Lseek(fd, pos, SEEK_SET) == -1) {
 139         JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
 140     }
 141 }
 142 
 143 JNIEXPORT void JNICALL
 144 Java_java_io_RandomAccessFile_setLength(JNIEnv *env, jobject this,
 145                                         jlong newLength)
 146 {