1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
4392 return ::_fdopen(fd, mode); |
4392 return ::_fdopen(fd, mode); |
4393 } |
4393 } |
4394 |
4394 |
4395 // Is a (classpath) directory empty? |
4395 // Is a (classpath) directory empty? |
4396 bool os::dir_is_empty(const char* path) { |
4396 bool os::dir_is_empty(const char* path) { |
4397 WIN32_FIND_DATA fd; |
4397 char* search_path = (char*)os::malloc(strlen(path) + 3, mtInternal); |
4398 HANDLE f = FindFirstFile(path, &fd); |
4398 if (search_path == NULL) { |
4399 if (f == INVALID_HANDLE_VALUE) { |
4399 errno = ENOMEM; |
4400 return true; |
4400 return false; |
4401 } |
4401 } |
4402 FindClose(f); |
4402 strcpy(search_path, path); |
4403 return false; |
4403 // Append "*", or possibly "\\*", to path |
|
4404 if (path[1] == ':' && |
|
4405 (path[2] == '\0' || |
|
4406 (path[2] == '\\' && path[3] == '\0'))) { |
|
4407 // No '\\' needed for cases like "Z:" or "Z:\" |
|
4408 strcat(search_path, "*"); |
|
4409 } |
|
4410 else { |
|
4411 strcat(search_path, "\\*"); |
|
4412 } |
|
4413 errno_t err = ERROR_SUCCESS; |
|
4414 wchar_t* wpath = create_unc_path(search_path, err); |
|
4415 if (err != ERROR_SUCCESS) { |
|
4416 if (wpath != NULL) { |
|
4417 destroy_unc_path(wpath); |
|
4418 } |
|
4419 os::free(search_path); |
|
4420 errno = err; |
|
4421 return false; |
|
4422 } |
|
4423 WIN32_FIND_DATAW fd; |
|
4424 HANDLE f = ::FindFirstFileW(wpath, &fd); |
|
4425 destroy_unc_path(wpath); |
|
4426 bool is_empty = true; |
|
4427 if (f != INVALID_HANDLE_VALUE) { |
|
4428 while (is_empty && ::FindNextFileW(f, &fd)) { |
|
4429 // An empty directory contains only the current directory file |
|
4430 // and the previous directory file. |
|
4431 if ((wcscmp(fd.cFileName, L".") != 0) && |
|
4432 (wcscmp(fd.cFileName, L"..") != 0)) { |
|
4433 is_empty = false; |
|
4434 } |
|
4435 } |
|
4436 FindClose(f); |
|
4437 } |
|
4438 os::free(search_path); |
|
4439 return is_empty; |
4404 } |
4440 } |
4405 |
4441 |
4406 // create binary file, rewriting existing file if required |
4442 // create binary file, rewriting existing file if required |
4407 int os::create_binary_file(const char* path, bool rewrite_existing) { |
4443 int os::create_binary_file(const char* path, bool rewrite_existing) { |
4408 int oflags = _O_CREAT | _O_WRONLY | _O_BINARY; |
4444 int oflags = _O_CREAT | _O_WRONLY | _O_BINARY; |