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

src/hotspot/os/windows/os_windows.cpp

Print this page

        

*** 4392,4408 **** return ::_fdopen(fd, mode); } // Is a (classpath) directory empty? bool os::dir_is_empty(const char* path) { ! WIN32_FIND_DATA fd; ! HANDLE f = FindFirstFile(path, &fd); ! if (f == INVALID_HANDLE_VALUE) { ! return true; } ! FindClose(f); return false; } // create binary file, rewriting existing file if required int os::create_binary_file(const char* path, bool rewrite_existing) { int oflags = _O_CREAT | _O_WRONLY | _O_BINARY; --- 4392,4446 ---- return ::_fdopen(fd, mode); } // Is a (classpath) directory empty? bool os::dir_is_empty(const char* path) { ! bool is_empty = false; ! char* search_path = (char*)os::malloc(strlen(path) + 3, mtInternal); ! if (search_path == NULL) { ! errno = ENOMEM; ! return false; } ! strcpy(search_path, path); ! // Append "*", or possibly "\\*", to path ! if (path[1] == ':' && ! (path[2] == '\0' || ! (path[2] == '\\' && path[3] == '\0'))) { ! // No '\\' needed for cases like "Z:" or "Z:\" ! strcat(search_path, "*"); ! } ! else { ! strcat(search_path, "\\*"); ! } ! errno_t err = ERROR_SUCCESS; ! wchar_t* wpath = create_unc_path(search_path, err); ! if (err != ERROR_SUCCESS) { ! if (wpath != NULL) { ! destroy_unc_path(wpath); ! } ! os::free(search_path); ! errno = err; return false; + } + WIN32_FIND_DATAW fd; + HANDLE f = FindFirstFileW(wpath, &fd); + destroy_unc_path(wpath); + if (f == INVALID_HANDLE_VALUE) { + is_empty = true; + } else { + int num_files = 0; + do { + num_files++; + } while (FindNextFileW(f, &fd)); + // An empty directory contains only the current directory file + // and the previous directory file. + is_empty = ((wcscmp(fd.cFileName, L".") == 0) || + (wcscmp(fd.cFileName, L"..") == 0)) && (num_files == 2); + FindClose(f); + } + free(search_path); + return is_empty; } // create binary file, rewriting existing file if required int os::create_binary_file(const char* path, bool rewrite_existing) { int oflags = _O_CREAT | _O_WRONLY | _O_BINARY;
src/hotspot/os/windows/os_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File