8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64

Reviewed-by: bsrbnd, mbaesken, bchristi, simonis
This commit is contained in:
Brian Burkhalter 2018-08-30 12:39:26 -07:00
parent 091aff1178
commit 67b2c6fc66
7 changed files with 50 additions and 38 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -100,6 +100,14 @@
#include <dirent.h> #include <dirent.h>
#endif /* Unix */ #endif /* Unix */
#if defined(_AIX)
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif
static int static int
exists(const char* filename) exists(const char* filename)
{ {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,6 +58,14 @@
#include <procfs.h> #include <procfs.h>
#endif #endif
#if defined(_AIX)
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif
/** /**
* This file contains the implementation of the native ProcessHandleImpl * This file contains the implementation of the native ProcessHandleImpl
* functions which are common to all Unix variants. * functions which are common to all Unix variants.

View file

@ -50,11 +50,6 @@
} while((_result == -1) && (errno == EINTR)); \ } while((_result == -1) && (errno == EINTR)); \
} while(0) } while(0)
#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
#define readdir64 readdir
#endif
#if !defined(__solaris__) || defined(__sparcv9) || defined(amd64) #if !defined(__solaris__) || defined(__sparcv9) || defined(amd64)
#define fileopen fopen #define fileopen fopen
#define filegets fgets #define filegets fgets
@ -121,7 +116,7 @@ findZoneinfoFile(char *buf, size_t size, const char *dir)
{ {
DIR *dirp = NULL; DIR *dirp = NULL;
struct stat statbuf; struct stat statbuf;
struct dirent64 *dp = NULL; struct dirent *dp = NULL;
char *pathname = NULL; char *pathname = NULL;
int fd = -1; int fd = -1;
char *dbuf = NULL; char *dbuf = NULL;
@ -133,7 +128,7 @@ findZoneinfoFile(char *buf, size_t size, const char *dir)
return NULL; return NULL;
} }
while ((dp = readdir64(dirp)) != NULL) { while ((dp = readdir(dirp)) != NULL) {
/* /*
* Skip '.' and '..' (and possibly other .* files) * Skip '.' and '..' (and possibly other .* files)
*/ */

View file

@ -55,8 +55,11 @@
#define NAME_MAX MAXNAMLEN #define NAME_MAX MAXNAMLEN
#endif #endif
#define DIR DIR64 #define DIR DIR64
#define dirent dirent64
#define opendir opendir64 #define opendir opendir64
#define readdir readdir64
#define closedir closedir64 #define closedir closedir64
#define stat stat64
#endif #endif
#if defined(__solaris__) && !defined(NAME_MAX) #if defined(__solaris__) && !defined(NAME_MAX)
@ -64,9 +67,6 @@
#endif #endif
#if defined(_ALLBSD_SOURCE) #if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
#define readdir64 readdir
#define stat64 stat
#ifndef MACOSX #ifndef MACOSX
#define statvfs64 statvfs #define statvfs64 statvfs
#endif #endif
@ -121,8 +121,8 @@ Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
static jboolean static jboolean
statMode(const char *path, int *mode) statMode(const char *path, int *mode)
{ {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
*mode = sb.st_mode; *mode = sb.st_mode;
return JNI_TRUE; return JNI_TRUE;
} }
@ -229,8 +229,8 @@ Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
#if defined(_AIX) #if defined(_AIX)
rv = (jlong)sb.st_mtime * 1000; rv = (jlong)sb.st_mtime * 1000;
rv += (jlong)sb.st_mtime_n / 1000000; rv += (jlong)sb.st_mtime_n / 1000000;
@ -254,8 +254,8 @@ Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
rv = sb.st_size; rv = sb.st_size;
} }
} END_PLATFORM_STRING(env, path); } END_PLATFORM_STRING(env, path);
@ -311,7 +311,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
jobject file) jobject file)
{ {
DIR *dir = NULL; DIR *dir = NULL;
struct dirent64 *ptr; struct dirent *ptr;
int len, maxlen; int len, maxlen;
jobjectArray rv, old; jobjectArray rv, old;
jclass str_class; jclass str_class;
@ -331,7 +331,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
if (rv == NULL) goto error; if (rv == NULL) goto error;
/* Scan the directory */ /* Scan the directory */
while ((ptr = readdir64(dir)) != NULL) { while ((ptr = readdir(dir)) != NULL) {
jstring name; jstring name;
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, "..")) if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
continue; continue;
@ -408,9 +408,9 @@ Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
jboolean rv = JNI_FALSE; jboolean rv = JNI_FALSE;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
struct timeval tv[2]; struct timeval tv[2];
/* Preserve access time */ /* Preserve access time */

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -66,12 +66,12 @@ isAsciiDigit(char c)
/* AIX does not understand '/proc/self' - it requires the real process ID */ /* AIX does not understand '/proc/self' - it requires the real process ID */
#define FD_DIR aix_fd_dir #define FD_DIR aix_fd_dir
#define DIR DIR64 #define DIR DIR64
#define dirent dirent64
#define opendir opendir64 #define opendir opendir64
#define readdir readdir64
#define closedir closedir64 #define closedir closedir64
#elif defined(_ALLBSD_SOURCE) #elif defined(_ALLBSD_SOURCE)
#define FD_DIR "/dev/fd" #define FD_DIR "/dev/fd"
#define dirent64 dirent
#define readdir64 readdir
#else #else
#define FD_DIR "/proc/self/fd" #define FD_DIR "/proc/self/fd"
#endif #endif
@ -80,7 +80,7 @@ int
closeDescriptors(void) closeDescriptors(void)
{ {
DIR *dp; DIR *dp;
struct dirent64 *dirp; struct dirent *dirp;
int from_fd = FAIL_FILENO + 1; int from_fd = FAIL_FILENO + 1;
/* We're trying to close all file descriptors, but opendir() might /* We're trying to close all file descriptors, but opendir() might
@ -102,10 +102,7 @@ closeDescriptors(void)
if ((dp = opendir(FD_DIR)) == NULL) if ((dp = opendir(FD_DIR)) == NULL)
return 0; return 0;
/* We use readdir64 instead of readdir to work around Solaris bug while ((dirp = readdir(dp)) != NULL) {
* 6395699: /proc/self/fd fails to report file descriptors >= 1024 on Solaris 9
*/
while ((dirp = readdir64(dp)) != NULL) {
int fd; int fd;
if (isAsciiDigit(dirp->d_name[0]) && if (isAsciiDigit(dirp->d_name[0]) &&
(fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2) (fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2)

View file

@ -71,7 +71,6 @@
#define open64 open #define open64 open
#define fstat64 fstat #define fstat64 fstat
#define lstat64 lstat #define lstat64 lstat
#define dirent64 dirent
#define readdir64 readdir #define readdir64 readdir
#endif #endif
@ -83,7 +82,9 @@
#if defined(_AIX) #if defined(_AIX)
#define DIR DIR64 #define DIR DIR64
#define dirent dirent64
#define opendir opendir64 #define opendir opendir64
#define readdir readdir64
#define closedir closedir64 #define closedir closedir64
#endif #endif
@ -729,10 +730,10 @@ Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong di
JNIEXPORT jbyteArray JNICALL JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) { Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
DIR* dirp = jlong_to_ptr(value); DIR* dirp = jlong_to_ptr(value);
struct dirent64* ptr; struct dirent* ptr;
errno = 0; errno = 0;
ptr = readdir64(dirp); ptr = readdir(dirp);
if (ptr == NULL) { if (ptr == NULL) {
if (errno != 0) { if (errno != 0) {
throwUnixException(env, errno); throwUnixException(env, errno);

View file

@ -74,9 +74,12 @@ static jlong page_size = 0;
#endif /* _ALLBSD_SOURCE */ #endif /* _ALLBSD_SOURCE */
#if defined(_ALLBSD_SOURCE) #if defined(_AIX)
#define dirent64 dirent #define DIR DIR64
#define readdir64 readdir #define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif #endif
// true = get available swap in bytes // true = get available swap in bytes
@ -423,7 +426,7 @@ Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0
return (100); return (100);
#else /* solaris/linux */ #else /* solaris/linux */
DIR *dirp; DIR *dirp;
struct dirent64* dentp; struct dirent* dentp;
jlong fds = 0; jlong fds = 0;
#if defined(_AIX) #if defined(_AIX)
@ -443,7 +446,7 @@ Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0
// iterate through directory entries, skipping '.' and '..' // iterate through directory entries, skipping '.' and '..'
// each entry represents an open file descriptor. // each entry represents an open file descriptor.
while ((dentp = readdir64(dirp)) != NULL) { while ((dentp = readdir(dirp)) != NULL) {
if (isdigit(dentp->d_name[0])) { if (isdigit(dentp->d_name[0])) {
fds++; fds++;
} }