< prev index next >
src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2008, 2017, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 70,80 ****
#define open64 open
#define fstat64 fstat
#define lstat64 lstat
#define dirent64 dirent
! #define readdir64_r readdir_r
#endif
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
--- 70,80 ----
#define open64 open
#define fstat64 fstat
#define lstat64 lstat
#define dirent64 dirent
! #define readdir64 readdir
#endif
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
*** 423,435 ****
return fd;
}
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);
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
jlong address, jint nbytes)
--- 423,443 ----
return fd;
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_close0(JNIEnv* env, jclass this, jint fd) {
! 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
Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd,
jlong address, jint nbytes)
*** 718,763 ****
}
}
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);
! /* 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;
}
- #endif
-
- if (res != 0) {
- throwUnixException(env, res);
- return NULL;
- } else {
- if (result == NULL) {
return NULL;
} else {
jsize len = strlen(ptr->d_name);
jbyteArray bytes = (*env)->NewByteArray(env, len);
if (bytes != NULL) {
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)(ptr->d_name));
}
return bytes;
}
- }
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_mkdir0(JNIEnv* env, jclass this,
jlong pathAddress, jint mode)
--- 726,753 ----
}
}
JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
DIR* dirp = jlong_to_ptr(value);
+ struct dirent64* ptr;
! errno = 0;
! ptr = readdir64(dirp);
! if (ptr == NULL) {
! if (errno != 0) {
! throwUnixException(env, errno);
}
return NULL;
} else {
jsize len = strlen(ptr->d_name);
jbyteArray bytes = (*env)->NewByteArray(env, len);
if (bytes != NULL) {
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)(ptr->d_name));
}
return bytes;
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_mkdir0(JNIEnv* env, jclass this,
jlong pathAddress, jint mode)
< prev index next >