src/hotspot/os/windows/os_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/os/windows

src/hotspot/os/windows/os_windows.cpp

Print this page




4377       os::free(pathbuf);
4378       errno = err;
4379       return -1;
4380     }
4381     ret = ::_wopen(wpath, oflag | O_BINARY | O_NOINHERIT, mode);
4382     if (ret == -1) {
4383       errno = ::GetLastError();
4384     }
4385     destroy_unc_path(wpath);
4386   }
4387   os::free(pathbuf);
4388   return ret;
4389 }
4390 
4391 FILE* os::open(int fd, const char* mode) {
4392   return ::_fdopen(fd, mode);
4393 }
4394 
4395 // Is a (classpath) directory empty?
4396 bool os::dir_is_empty(const char* path) {
4397   WIN32_FIND_DATA fd;
4398   HANDLE f = FindFirstFile(path, &fd);
4399   if (f == INVALID_HANDLE_VALUE) {
4400     return true;

4401   }
4402   FindClose(f);


















4403   return false;



















4404 }
4405 
4406 // create binary file, rewriting existing file if required
4407 int os::create_binary_file(const char* path, bool rewrite_existing) {
4408   int oflags = _O_CREAT | _O_WRONLY | _O_BINARY;
4409   if (!rewrite_existing) {
4410     oflags |= _O_EXCL;
4411   }
4412   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4413 }
4414 
4415 // return current position of file pointer
4416 jlong os::current_file_offset(int fd) {
4417   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4418 }
4419 
4420 // move file pointer to the specified offset
4421 jlong os::seek_to_file_offset(int fd, jlong offset) {
4422   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4423 }




4377       os::free(pathbuf);
4378       errno = err;
4379       return -1;
4380     }
4381     ret = ::_wopen(wpath, oflag | O_BINARY | O_NOINHERIT, mode);
4382     if (ret == -1) {
4383       errno = ::GetLastError();
4384     }
4385     destroy_unc_path(wpath);
4386   }
4387   os::free(pathbuf);
4388   return ret;
4389 }
4390 
4391 FILE* os::open(int fd, const char* mode) {
4392   return ::_fdopen(fd, mode);
4393 }
4394 
4395 // Is a (classpath) directory empty?
4396 bool os::dir_is_empty(const char* path) {
4397   bool is_empty = false;
4398   char* search_path = (char*)os::malloc(strlen(path) + 3, mtInternal);
4399   if (search_path == NULL) {
4400     errno = ENOMEM;
4401     return false;
4402   }
4403   strcpy(search_path, path);
4404   // Append "*", or possibly "\\*", to path
4405   if (path[1] == ':' &&
4406     (path[2] == '\0' ||
4407     (path[2] == '\\' && path[3] == '\0'))) {
4408     // No '\\' needed for cases like "Z:" or "Z:\"
4409     strcat(search_path, "*");
4410   }
4411   else {
4412     strcat(search_path, "\\*");
4413   }
4414   errno_t err = ERROR_SUCCESS;
4415   wchar_t* wpath = create_unc_path(search_path, err);
4416   if (err != ERROR_SUCCESS) {
4417     if (wpath != NULL) {
4418       destroy_unc_path(wpath);
4419     }
4420     os::free(search_path);
4421     errno = err;
4422     return false;
4423   }
4424   WIN32_FIND_DATAW fd;
4425   HANDLE f = FindFirstFileW(wpath, &fd);
4426   destroy_unc_path(wpath);
4427   if (f == INVALID_HANDLE_VALUE) {
4428     is_empty = true;
4429   } else {
4430     int num_files = 0;
4431     do {
4432       num_files++;
4433     } while (FindNextFileW(f, &fd));
4434     // An empty directory contains only the current directory file
4435     // and the previous directory file.
4436     is_empty = ((wcscmp(fd.cFileName, L".") == 0) ||
4437       (wcscmp(fd.cFileName, L"..") == 0)) && (num_files == 2);
4438     FindClose(f);
4439   }
4440   free(search_path);
4441   return is_empty;
4442 }
4443 
4444 // create binary file, rewriting existing file if required
4445 int os::create_binary_file(const char* path, bool rewrite_existing) {
4446   int oflags = _O_CREAT | _O_WRONLY | _O_BINARY;
4447   if (!rewrite_existing) {
4448     oflags |= _O_EXCL;
4449   }
4450   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4451 }
4452 
4453 // return current position of file pointer
4454 jlong os::current_file_offset(int fd) {
4455   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4456 }
4457 
4458 // move file pointer to the specified offset
4459 jlong os::seek_to_file_offset(int fd, jlong offset) {
4460   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4461 }


src/hotspot/os/windows/os_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File