8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64
authorbpb
Thu, 30 Aug 2018 12:39:26 -0700
changeset 51597 4c78f4fd8370
parent 51596 b8eea2a7569a
child 51598 c88019b32bc4
8207744: Clean up inconsistent use of opendir/closedir versus opendir64/closedir64 Reviewed-by: bsrbnd, mbaesken, bchristi, simonis
src/java.base/share/native/libjli/wildcard.c
src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
src/java.base/unix/native/libjava/TimeZone_md.c
src/java.base/unix/native/libjava/UnixFileSystem_md.c
src/java.base/unix/native/libjava/childproc.c
src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
--- a/src/java.base/share/native/libjli/wildcard.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/share/native/libjli/wildcard.c	Thu Aug 30 12:39:26 2018 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -100,6 +100,14 @@
 #include <dirent.h>
 #endif /* Unix */
 
+#if defined(_AIX)
+  #define DIR DIR64
+  #define dirent dirent64
+  #define opendir opendir64
+  #define readdir readdir64
+  #define closedir closedir64
+#endif
+
 static int
 exists(const char* filename)
 {
--- a/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Thu Aug 30 12:39:26 2018 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,6 +58,14 @@
 #include <procfs.h>
 #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
  * functions which are common to all Unix variants.
--- a/src/java.base/unix/native/libjava/TimeZone_md.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/unix/native/libjava/TimeZone_md.c	Thu Aug 30 12:39:26 2018 -0700
@@ -50,11 +50,6 @@
   } while((_result == -1) && (errno == EINTR)); \
 } while(0)
 
-#if defined(_ALLBSD_SOURCE)
-#define dirent64 dirent
-#define readdir64 readdir
-#endif
-
 #if !defined(__solaris__) || defined(__sparcv9) || defined(amd64)
 #define fileopen        fopen
 #define filegets        fgets
@@ -121,7 +116,7 @@
 {
     DIR *dirp = NULL;
     struct stat statbuf;
-    struct dirent64 *dp = NULL;
+    struct dirent *dp = NULL;
     char *pathname = NULL;
     int fd = -1;
     char *dbuf = NULL;
@@ -133,7 +128,7 @@
         return NULL;
     }
 
-    while ((dp = readdir64(dirp)) != NULL) {
+    while ((dp = readdir(dirp)) != NULL) {
         /*
          * Skip '.' and '..' (and possibly other .* files)
          */
--- a/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Thu Aug 30 12:39:26 2018 -0700
@@ -55,8 +55,11 @@
     #define NAME_MAX MAXNAMLEN
   #endif
   #define DIR DIR64
+  #define dirent dirent64
   #define opendir opendir64
+  #define readdir readdir64
   #define closedir closedir64
+  #define stat stat64
 #endif
 
 #if defined(__solaris__) && !defined(NAME_MAX)
@@ -64,9 +67,6 @@
 #endif
 
 #if defined(_ALLBSD_SOURCE)
-  #define dirent64 dirent
-  #define readdir64 readdir
-  #define stat64 stat
   #ifndef MACOSX
     #define statvfs64 statvfs
   #endif
@@ -121,8 +121,8 @@
 static jboolean
 statMode(const char *path, int *mode)
 {
-    struct stat64 sb;
-    if (stat64(path, &sb) == 0) {
+    struct stat sb;
+    if (stat(path, &sb) == 0) {
         *mode = sb.st_mode;
         return JNI_TRUE;
     }
@@ -229,8 +229,8 @@
     jlong rv = 0;
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
-        struct stat64 sb;
-        if (stat64(path, &sb) == 0) {
+        struct stat sb;
+        if (stat(path, &sb) == 0) {
 #if defined(_AIX)
             rv =  (jlong)sb.st_mtime * 1000;
             rv += (jlong)sb.st_mtime_n / 1000000;
@@ -254,8 +254,8 @@
     jlong rv = 0;
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
-        struct stat64 sb;
-        if (stat64(path, &sb) == 0) {
+        struct stat sb;
+        if (stat(path, &sb) == 0) {
             rv = sb.st_size;
         }
     } END_PLATFORM_STRING(env, path);
@@ -311,7 +311,7 @@
                                  jobject file)
 {
     DIR *dir = NULL;
-    struct dirent64 *ptr;
+    struct dirent *ptr;
     int len, maxlen;
     jobjectArray rv, old;
     jclass str_class;
@@ -331,7 +331,7 @@
     if (rv == NULL) goto error;
 
     /* Scan the directory */
-    while ((ptr = readdir64(dir)) != NULL) {
+    while ((ptr = readdir(dir)) != NULL) {
         jstring name;
         if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
             continue;
@@ -408,9 +408,9 @@
     jboolean rv = JNI_FALSE;
 
     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];
 
             /* Preserve access time */
--- a/src/java.base/unix/native/libjava/childproc.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/unix/native/libjava/childproc.c	Thu Aug 30 12:39:26 2018 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -66,12 +66,12 @@
   /* AIX does not understand '/proc/self' - it requires the real process ID */
   #define FD_DIR aix_fd_dir
   #define DIR DIR64
+  #define dirent dirent64
   #define opendir opendir64
+  #define readdir readdir64
   #define closedir closedir64
 #elif defined(_ALLBSD_SOURCE)
   #define FD_DIR "/dev/fd"
-  #define dirent64 dirent
-  #define readdir64 readdir
 #else
   #define FD_DIR "/proc/self/fd"
 #endif
@@ -80,7 +80,7 @@
 closeDescriptors(void)
 {
     DIR *dp;
-    struct dirent64 *dirp;
+    struct dirent *dirp;
     int from_fd = FAIL_FILENO + 1;
 
     /* We're trying to close all file descriptors, but opendir() might
@@ -102,10 +102,7 @@
     if ((dp = opendir(FD_DIR)) == NULL)
         return 0;
 
-    /* We use readdir64 instead of readdir to work around Solaris bug
-     * 6395699: /proc/self/fd fails to report file descriptors >= 1024 on Solaris 9
-     */
-    while ((dirp = readdir64(dp)) != NULL) {
+    while ((dirp = readdir(dp)) != NULL) {
         int fd;
         if (isAsciiDigit(dirp->d_name[0]) &&
             (fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2)
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Thu Aug 30 12:39:26 2018 -0700
@@ -71,7 +71,6 @@
 #define open64 open
 #define fstat64 fstat
 #define lstat64 lstat
-#define dirent64 dirent
 #define readdir64 readdir
 #endif
 
@@ -83,7 +82,9 @@
 
 #if defined(_AIX)
   #define DIR DIR64
+  #define dirent dirent64
   #define opendir opendir64
+  #define readdir readdir64
   #define closedir closedir64
 #endif
 
@@ -729,10 +730,10 @@
 JNIEXPORT jbyteArray JNICALL
 Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) {
     DIR* dirp = jlong_to_ptr(value);
-    struct dirent64* ptr;
+    struct dirent* ptr;
 
     errno = 0;
-    ptr = readdir64(dirp);
+    ptr = readdir(dirp);
     if (ptr == NULL) {
         if (errno != 0) {
             throwUnixException(env, errno);
--- a/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c	Thu Aug 30 11:53:49 2018 -0700
+++ b/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c	Thu Aug 30 12:39:26 2018 -0700
@@ -74,9 +74,12 @@
 
 #endif /* _ALLBSD_SOURCE */
 
-#if defined(_ALLBSD_SOURCE)
-  #define dirent64 dirent
-  #define readdir64 readdir
+#if defined(_AIX)
+  #define DIR DIR64
+  #define dirent dirent64
+  #define opendir opendir64
+  #define readdir readdir64
+  #define closedir closedir64
 #endif
 
 // true = get available swap in bytes
@@ -423,7 +426,7 @@
     return (100);
 #else /* solaris/linux */
     DIR *dirp;
-    struct dirent64* dentp;
+    struct dirent* dentp;
     jlong fds = 0;
 
 #if defined(_AIX)
@@ -443,7 +446,7 @@
 
     // iterate through directory entries, skipping '.' and '..'
     // each entry represents an open file descriptor.
-    while ((dentp = readdir64(dirp)) != NULL) {
+    while ((dentp = readdir(dirp)) != NULL) {
         if (isdigit(dentp->d_name[0])) {
             fds++;
         }