src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

Print this page
rev 10532 : 8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

*** 331,341 **** Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) { int res = -1; RESTARTABLE(dup((int)fd), res); ! if (fd == -1) { throwUnixException(env, errno); } return (jint)res; } --- 331,341 ---- Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) { int res = -1; RESTARTABLE(dup((int)fd), res); ! if (res == -1) { throwUnixException(env, errno); } return (jint)res; }
*** 359,375 **** } JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) { - int res; FILE* fp = jlong_to_ptr(stream); ! do { ! res = fclose(fp); ! } while (res == EOF && errno == EINTR); ! if (res == EOF) { throwUnixException(env, errno); } } JNIEXPORT jint JNICALL --- 359,376 ---- } JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) { FILE* fp = jlong_to_ptr(stream); ! /* NOTE: fclose() wrapper is only used with read-only streams. ! * If it ever is used with write streams, it might be better to add ! * RESTARTABLE(fflush(fp)) before closing, to make sure the stream ! * is completely written even if fclose() failed. ! */ ! if (fclose(fp) == EOF && errno != EINTR) { throwUnixException(env, errno); } } JNIEXPORT jint JNICALL
*** 673,687 **** return ptr_to_jlong(dir); } JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { - int err; DIR* dirp = jlong_to_ptr(dir); ! RESTARTABLE(closedir(dirp), err); ! if (errno == -1) { throwUnixException(env, errno); } } JNIEXPORT jbyteArray JNICALL --- 674,686 ---- return ptr_to_jlong(dir); } JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { DIR* dirp = jlong_to_ptr(dir); ! if (closedir(dirp) == -1 && errno != EINTR) { throwUnixException(env, errno); } } JNIEXPORT jbyteArray JNICALL