< prev index next >

src/java.base/unix/native/libjava/io_util_md.c

Print this page
rev 50500 : [mq]: JDK-8204663-clean-up-after-JDK-8187631


 104         while ((p > ps) && (*p == '/'))
 105             *p-- = '\0';
 106 #endif
 107         fd = handleOpen(ps, flags, 0666);
 108         if (fd != -1) {
 109             jobject fdobj;
 110             jboolean append;
 111             SET_FD(this, fd, fid);
 112 
 113             fdobj = (*env)->GetObjectField(env, this, fid);
 114             if (fdobj != NULL) {
 115                 append = (flags & O_APPEND) == 0 ? JNI_FALSE : JNI_TRUE;
 116                 (*env)->SetBooleanField(env, fdobj, IO_append_fdID, append);
 117             }
 118         } else {
 119             throwFileNotFoundException(env, path);
 120         }
 121     } END_PLATFORM_STRING(env, ps);
 122 }
 123 
 124 void
 125 fileClose(JNIEnv *env, jobject this, jfieldID fid)
 126 {
 127     jobject fileDescriptor = (*env)->GetObjectField(env, (this), (fid));
 128     if (fileDescriptor == NULL) {
 129         return;
 130     }
 131     fileDescriptorClose(env, fileDescriptor);
 132 }
 133 
 134 // Function to close the fd held by this FileDescriptor and set fd to -1.
 135 void
 136 fileDescriptorClose(JNIEnv *env, jobject this)
 137 {
 138     FD fd = (*env)->GetIntField(env, this, IO_fd_fdID);
 139     if ((*env)->ExceptionOccurred(env)) {
 140         return;
 141     }
 142 
 143     if (fd == -1) {
 144         return;     // already closed and set to -1
 145     }
 146 
 147     /* Set the fd to -1 before closing it so that the timing window
 148      * of other threads using the wrong fd (closed but recycled fd,
 149      * that gets re-opened with some other filename) is reduced.
 150      * Practically the chance of its occurance is low, however, we are
 151      * taking extra precaution over here.
 152      */
 153     (*env)->SetIntField(env, this, IO_fd_fdID, -1);




 104         while ((p > ps) && (*p == '/'))
 105             *p-- = '\0';
 106 #endif
 107         fd = handleOpen(ps, flags, 0666);
 108         if (fd != -1) {
 109             jobject fdobj;
 110             jboolean append;
 111             SET_FD(this, fd, fid);
 112 
 113             fdobj = (*env)->GetObjectField(env, this, fid);
 114             if (fdobj != NULL) {
 115                 append = (flags & O_APPEND) == 0 ? JNI_FALSE : JNI_TRUE;
 116                 (*env)->SetBooleanField(env, fdobj, IO_append_fdID, append);
 117             }
 118         } else {
 119             throwFileNotFoundException(env, path);
 120         }
 121     } END_PLATFORM_STRING(env, ps);
 122 }
 123 










 124 // Function to close the fd held by this FileDescriptor and set fd to -1.
 125 void
 126 fileDescriptorClose(JNIEnv *env, jobject this)
 127 {
 128     FD fd = (*env)->GetIntField(env, this, IO_fd_fdID);
 129     if ((*env)->ExceptionOccurred(env)) {
 130         return;
 131     }
 132 
 133     if (fd == -1) {
 134         return;     // already closed and set to -1
 135     }
 136 
 137     /* Set the fd to -1 before closing it so that the timing window
 138      * of other threads using the wrong fd (closed but recycled fd,
 139      * that gets re-opened with some other filename) is reduced.
 140      * Practically the chance of its occurance is low, however, we are
 141      * taking extra precaution over here.
 142      */
 143     (*env)->SetIntField(env, this, IO_fd_fdID, -1);


< prev index next >