Skip to content
Snippets Groups Projects
Commit df45a1b5 authored by Alan Bateman's avatar Alan Bateman
Browse files

8207340: (fs) UnixNativeDispatcher close and readdir usages should be fixed

Reviewed-by: bpb
parent a376d5da
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -72,7 +72,7 @@
#define fstat64 fstat
#define lstat64 lstat
#define dirent64 dirent
#define readdir64_r readdir_r
#define readdir64 readdir
#endif
#include "jni.h"
......@@ -425,9 +425,17 @@ Java_sun_nio_fs_UnixNativeDispatcher_openat0(JNIEnv* env, jclass this, jint dfd,
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_close0(JNIEnv* env, jclass this, jint fd) {
int err;
/* TDB - need to decide if EIO and other errors should cause exception */
RESTARTABLE(close((int)fd), err);
int res;
#if defined(_AIX)
/* AIX allows close to be restarted after EINTR */
RESTARTABLE(close((int)fd), res);
#else
res = close((int)fd);
#endif
if (res == -1 && errno != EINTR) {
throwUnixException(env, errno);
}
}
JNIEXPORT jint JNICALL
......@@ -720,32 +728,15 @@ Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong di
JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
struct dirent64* result;
struct {
struct dirent64 buf;
char name_extra[PATH_MAX + 1 - sizeof result->d_name];
} entry;
struct dirent64* ptr = &entry.buf;
int res;
DIR* dirp = jlong_to_ptr(value);
struct dirent64* ptr;
/* EINTR not listed as a possible error */
/* TDB: reentrant version probably not required here */
res = readdir64_r(dirp, ptr, &result);
#ifdef _AIX
/* On AIX, readdir_r() returns EBADF (i.e. '9') and sets 'result' to NULL for the */
/* directory stream end. Otherwise, 'errno' will contain the error code. */
if (res != 0) {
res = (result == NULL && res == EBADF) ? 0 : errno;
errno = 0;
ptr = readdir64(dirp);
if (ptr == NULL) {
if (errno != 0) {
throwUnixException(env, errno);
}
#endif
if (res != 0) {
throwUnixException(env, res);
return NULL;
} else {
if (result == NULL) {
return NULL;
} else {
jsize len = strlen(ptr->d_name);
......@@ -756,7 +747,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong val
return bytes;
}
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_mkdir0(JNIEnv* env, jclass this,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment