< prev index next >

src/os/solaris/vm/os_solaris.cpp

Print this page




4790 
4791   dir = opendir(path);
4792   if (dir == NULL) return true;
4793 
4794   // Scan the directory
4795   bool result = true;
4796   char buf[sizeof(struct dirent) + MAX_PATH];
4797   struct dirent *dbuf = (struct dirent *) buf;
4798   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
4799     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4800       result = false;
4801     }
4802   }
4803   closedir(dir);
4804   return result;
4805 }
4806 
4807 // This code originates from JDK's sysOpen and open64_w
4808 // from src/solaris/hpi/src/system_md.c
4809 
4810 #ifndef O_DELETE
4811   #define O_DELETE 0x10000
4812 #endif
4813 
4814 // Open a file. Unlink the file immediately after open returns
4815 // if the specified oflag has the O_DELETE flag set.
4816 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
4817 
4818 int os::open(const char *path, int oflag, int mode) {
4819   if (strlen(path) > MAX_PATH - 1) {
4820     errno = ENAMETOOLONG;
4821     return -1;
4822   }
4823   int fd;
4824   int o_delete = (oflag & O_DELETE);
4825   oflag = oflag & ~O_DELETE;
4826 
4827   fd = ::open64(path, oflag, mode);
4828   if (fd == -1) return -1;
4829 
4830   // If the open succeeded, the file might still be a directory
4831   {
4832     struct stat64 buf64;
4833     int ret = ::fstat64(fd, &buf64);
4834     int st_mode = buf64.st_mode;
4835 
4836     if (ret != -1) {
4837       if ((st_mode & S_IFMT) == S_IFDIR) {
4838         errno = EISDIR;
4839         ::close(fd);
4840         return -1;
4841       }
4842     } else {
4843       ::close(fd);
4844       return -1;
4845     }


4901   // - might cause an fopen in the subprocess to fail on a system
4902   //   suffering from bug 1085341.
4903   //
4904   // (Yes, the default setting of the close-on-exec flag is a Unix
4905   // design flaw)
4906   //
4907   // See:
4908   // 1085341: 32-bit stdio routines should support file descriptors >255
4909   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4910   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4911   //
4912 #ifdef FD_CLOEXEC
4913   {
4914     int flags = ::fcntl(fd, F_GETFD);
4915     if (flags != -1) {
4916       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4917     }
4918   }
4919 #endif
4920 
4921   if (o_delete != 0) {
4922     ::unlink(path);
4923   }
4924   return fd;
4925 }
4926 
4927 // create binary file, rewriting existing file if required
4928 int os::create_binary_file(const char* path, bool rewrite_existing) {
4929   int oflags = O_WRONLY | O_CREAT;
4930   if (!rewrite_existing) {
4931     oflags |= O_EXCL;
4932   }
4933   return ::open64(path, oflags, S_IREAD | S_IWRITE);
4934 }
4935 
4936 // return current position of file pointer
4937 jlong os::current_file_offset(int fd) {
4938   return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4939 }
4940 
4941 // move file pointer to the specified offset
4942 jlong os::seek_to_file_offset(int fd, jlong offset) {
4943   return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);




4790 
4791   dir = opendir(path);
4792   if (dir == NULL) return true;
4793 
4794   // Scan the directory
4795   bool result = true;
4796   char buf[sizeof(struct dirent) + MAX_PATH];
4797   struct dirent *dbuf = (struct dirent *) buf;
4798   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
4799     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
4800       result = false;
4801     }
4802   }
4803   closedir(dir);
4804   return result;
4805 }
4806 
4807 // This code originates from JDK's sysOpen and open64_w
4808 // from src/solaris/hpi/src/system_md.c
4809 








4810 int os::open(const char *path, int oflag, int mode) {
4811   if (strlen(path) > MAX_PATH - 1) {
4812     errno = ENAMETOOLONG;
4813     return -1;
4814   }
4815   int fd;


4816 
4817   fd = ::open64(path, oflag, mode);
4818   if (fd == -1) return -1;
4819 
4820   // If the open succeeded, the file might still be a directory
4821   {
4822     struct stat64 buf64;
4823     int ret = ::fstat64(fd, &buf64);
4824     int st_mode = buf64.st_mode;
4825 
4826     if (ret != -1) {
4827       if ((st_mode & S_IFMT) == S_IFDIR) {
4828         errno = EISDIR;
4829         ::close(fd);
4830         return -1;
4831       }
4832     } else {
4833       ::close(fd);
4834       return -1;
4835     }


4891   // - might cause an fopen in the subprocess to fail on a system
4892   //   suffering from bug 1085341.
4893   //
4894   // (Yes, the default setting of the close-on-exec flag is a Unix
4895   // design flaw)
4896   //
4897   // See:
4898   // 1085341: 32-bit stdio routines should support file descriptors >255
4899   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4900   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4901   //
4902 #ifdef FD_CLOEXEC
4903   {
4904     int flags = ::fcntl(fd, F_GETFD);
4905     if (flags != -1) {
4906       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4907     }
4908   }
4909 #endif
4910 



4911   return fd;
4912 }
4913 
4914 // create binary file, rewriting existing file if required
4915 int os::create_binary_file(const char* path, bool rewrite_existing) {
4916   int oflags = O_WRONLY | O_CREAT;
4917   if (!rewrite_existing) {
4918     oflags |= O_EXCL;
4919   }
4920   return ::open64(path, oflags, S_IREAD | S_IWRITE);
4921 }
4922 
4923 // return current position of file pointer
4924 jlong os::current_file_offset(int fd) {
4925   return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4926 }
4927 
4928 // move file pointer to the specified offset
4929 jlong os::seek_to_file_offset(int fd, jlong offset) {
4930   return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);


< prev index next >