< prev index next >

src/os/aix/vm/os_aix.cpp

Print this page




4008   struct dirent *ptr;
4009 
4010   dir = opendir(path);
4011   if (dir == NULL) return true;
4012 
4013   /* Scan the directory */
4014   bool result = true;
4015   char buf[sizeof(struct dirent) + MAX_PATH];
4016   while (result && (ptr = ::readdir(dir)) != NULL) {
4017     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4018       result = false;
4019     }
4020   }
4021   closedir(dir);
4022   return result;
4023 }
4024 
4025 // This code originates from JDK's sysOpen and open64_w
4026 // from src/solaris/hpi/src/system_md.c
4027 
4028 #ifndef O_DELETE
4029 #define O_DELETE 0x10000
4030 #endif
4031 
4032 // Open a file. Unlink the file immediately after open returns
4033 // if the specified oflag has the O_DELETE flag set.
4034 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
4035 
4036 int os::open(const char *path, int oflag, int mode) {
4037 
4038   if (strlen(path) > MAX_PATH - 1) {
4039     errno = ENAMETOOLONG;
4040     return -1;
4041   }
4042   int fd;
4043   int o_delete = (oflag & O_DELETE);
4044   oflag = oflag & ~O_DELETE;
4045 
4046   fd = ::open64(path, oflag, mode);
4047   if (fd == -1) return -1;
4048 
4049   // If the open succeeded, the file might still be a directory.
4050   {
4051     struct stat64 buf64;
4052     int ret = ::fstat64(fd, &buf64);
4053     int st_mode = buf64.st_mode;
4054 
4055     if (ret != -1) {
4056       if ((st_mode & S_IFMT) == S_IFDIR) {
4057         errno = EISDIR;
4058         ::close(fd);
4059         return -1;
4060       }
4061     } else {
4062       ::close(fd);
4063       return -1;
4064     }


4075   //   descriptors, resulting in mysterious hangs, or
4076   //
4077   // - might cause an fopen in the subprocess to fail on a system
4078   //   suffering from bug 1085341.
4079   //
4080   // (Yes, the default setting of the close-on-exec flag is a Unix
4081   // design flaw.)
4082   //
4083   // See:
4084   // 1085341: 32-bit stdio routines should support file descriptors >255
4085   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4086   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4087 #ifdef FD_CLOEXEC
4088   {
4089     int flags = ::fcntl(fd, F_GETFD);
4090     if (flags != -1)
4091       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4092   }
4093 #endif
4094 
4095   if (o_delete != 0) {
4096     ::unlink(path);
4097   }
4098   return fd;
4099 }
4100 
4101 
4102 // create binary file, rewriting existing file if required
4103 int os::create_binary_file(const char* path, bool rewrite_existing) {
4104   int oflags = O_WRONLY | O_CREAT;
4105   if (!rewrite_existing) {
4106     oflags |= O_EXCL;
4107   }
4108   return ::open64(path, oflags, S_IREAD | S_IWRITE);
4109 }
4110 
4111 // return current position of file pointer
4112 jlong os::current_file_offset(int fd) {
4113   return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4114 }
4115 
4116 // move file pointer to the specified offset
4117 jlong os::seek_to_file_offset(int fd, jlong offset) {




4008   struct dirent *ptr;
4009 
4010   dir = opendir(path);
4011   if (dir == NULL) return true;
4012 
4013   /* Scan the directory */
4014   bool result = true;
4015   char buf[sizeof(struct dirent) + MAX_PATH];
4016   while (result && (ptr = ::readdir(dir)) != NULL) {
4017     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4018       result = false;
4019     }
4020   }
4021   closedir(dir);
4022   return result;
4023 }
4024 
4025 // This code originates from JDK's sysOpen and open64_w
4026 // from src/solaris/hpi/src/system_md.c
4027 








4028 int os::open(const char *path, int oflag, int mode) {
4029 
4030   if (strlen(path) > MAX_PATH - 1) {
4031     errno = ENAMETOOLONG;
4032     return -1;
4033   }
4034   int fd;


4035 
4036   fd = ::open64(path, oflag, mode);
4037   if (fd == -1) return -1;
4038 
4039   // If the open succeeded, the file might still be a directory.
4040   {
4041     struct stat64 buf64;
4042     int ret = ::fstat64(fd, &buf64);
4043     int st_mode = buf64.st_mode;
4044 
4045     if (ret != -1) {
4046       if ((st_mode & S_IFMT) == S_IFDIR) {
4047         errno = EISDIR;
4048         ::close(fd);
4049         return -1;
4050       }
4051     } else {
4052       ::close(fd);
4053       return -1;
4054     }


4065   //   descriptors, resulting in mysterious hangs, or
4066   //
4067   // - might cause an fopen in the subprocess to fail on a system
4068   //   suffering from bug 1085341.
4069   //
4070   // (Yes, the default setting of the close-on-exec flag is a Unix
4071   // design flaw.)
4072   //
4073   // See:
4074   // 1085341: 32-bit stdio routines should support file descriptors >255
4075   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4076   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4077 #ifdef FD_CLOEXEC
4078   {
4079     int flags = ::fcntl(fd, F_GETFD);
4080     if (flags != -1)
4081       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4082   }
4083 #endif
4084 



4085   return fd;
4086 }
4087 
4088 
4089 // create binary file, rewriting existing file if required
4090 int os::create_binary_file(const char* path, bool rewrite_existing) {
4091   int oflags = O_WRONLY | O_CREAT;
4092   if (!rewrite_existing) {
4093     oflags |= O_EXCL;
4094   }
4095   return ::open64(path, oflags, S_IREAD | S_IWRITE);
4096 }
4097 
4098 // return current position of file pointer
4099 jlong os::current_file_offset(int fd) {
4100   return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4101 }
4102 
4103 // move file pointer to the specified offset
4104 jlong os::seek_to_file_offset(int fd, jlong offset) {


< prev index next >