|
4 | 4 | #if defined(_WIN32)
|
5 | 5 | #include <windows.h>
|
6 | 6 | #include <fileapi.h>
|
7 |
| - #include <shlwapi.h> |
8 | 7 | #endif
|
9 | 8 |
|
10 | 9 | #if defined(__FreeBSD__)
|
|
41 | 40 | #include "walkdir.h"
|
42 | 41 | #include "pathsep.h"
|
43 | 42 |
|
44 |
| -#if !(defined(_WIN32) || defined(__serenity__)) |
45 |
| - #include "getdents.h" |
46 |
| -#endif |
47 |
| - |
48 | 43 | #if defined(_WIN32) || defined(__OpenBSD__)
|
49 | 44 | #include "path.h"
|
50 | 45 | #endif
|
@@ -466,126 +461,6 @@ int directory_exists(const char* const directory) {
|
466 | 461 |
|
467 | 462 | }
|
468 | 463 |
|
469 |
| -int directory_empty(const char* const directory) { |
470 |
| - /* |
471 |
| - Determines whether a specified path is an empty directory. |
472 |
| - |
473 |
| - Returns (1) if directory is empty, (0) if it does not, (-1) on error. |
474 |
| - */ |
475 |
| - |
476 |
| - #if defined(_WIN32) |
477 |
| - DWORD attributes = 0; |
478 |
| - BOOL status = FALSE; |
479 |
| - |
480 |
| - #if defined(_UNICODE) |
481 |
| - wchar_t* wdirectory = NULL; |
482 |
| - |
483 |
| - /* This prefix is required to support long paths in Windows 10+ */ |
484 |
| - const size_t prefixs = isabsolute(directory) ? wcslen(WIN10_LONG_PATH_PREFIX) : 0; |
485 |
| - |
486 |
| - const int wdirectorys = MultiByteToWideChar(CP_UTF8, 0, directory, -1, NULL, 0); |
487 |
| - |
488 |
| - if (wdirectorys == 0) { |
489 |
| - return -1; |
490 |
| - } |
491 |
| - |
492 |
| - wdirectory = malloc(prefixs + (size_t) wdirectorys); |
493 |
| - |
494 |
| - if (wdirectory == NULL) { |
495 |
| - return -1; |
496 |
| - } |
497 |
| - |
498 |
| - if (prefixs > 0) { |
499 |
| - wcscpy(wdirectory, WIN10_LONG_PATH_PREFIX); |
500 |
| - } |
501 |
| - |
502 |
| - if (MultiByteToWideChar(CP_UTF8, 0, directory, -1, wdirectory + prefixs, wdirectorys) == 0) { |
503 |
| - free(wdirectory); |
504 |
| - return -1; |
505 |
| - } |
506 |
| - |
507 |
| - attributes = GetFileAttributesW(wdirectory); |
508 |
| - #else |
509 |
| - attributes = GetFileAttributesA(directory); |
510 |
| - #endif |
511 |
| - |
512 |
| - if (attributes == INVALID_FILE_ATTRIBUTES) { |
513 |
| - #if defined(_UNICODE) |
514 |
| - free(wdirectory); |
515 |
| - #endif |
516 |
| - |
517 |
| - return -1; |
518 |
| - } |
519 |
| - |
520 |
| - if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
521 |
| - #if defined(_UNICODE) |
522 |
| - free(wdirectory); |
523 |
| - #endif |
524 |
| - |
525 |
| - return -1; |
526 |
| - } |
527 |
| - |
528 |
| - #if defined(_UNICODE) |
529 |
| - status = PathIsDirectoryEmptyW(wdirectory); |
530 |
| - #else |
531 |
| - status = PathIsDirectoryEmptyA(directory); |
532 |
| - #endif |
533 |
| - |
534 |
| - #if defined(_UNICODE) |
535 |
| - free(wdirectory); |
536 |
| - #endif |
537 |
| - |
538 |
| - return (int) status; |
539 |
| - #else |
540 |
| - #if !defined(__serenity__) |
541 |
| - long index = 0; |
542 |
| - |
543 |
| - directory_entry_t item; |
544 |
| - directory_entry_t items[3]; |
545 |
| - |
546 |
| - const int fd = open_dir(directory); |
547 |
| - |
548 |
| - if (fd == -1) { |
549 |
| - return -1; |
550 |
| - } |
551 |
| - |
552 |
| - while (1) { |
553 |
| - const ssize_t size = get_directory_entries(fd, (char*) items, sizeof(items)); |
554 |
| - |
555 |
| - if (size == 0) { |
556 |
| - close_dir(fd); |
557 |
| - break; |
558 |
| - } |
559 |
| - |
560 |
| - if (size == -1) { |
561 |
| - close_dir(fd); |
562 |
| - |
563 |
| - if (errno == EINVAL) { |
564 |
| - return 0; |
565 |
| - } |
566 |
| - |
567 |
| - return -1; |
568 |
| - } |
569 |
| - |
570 |
| - for (index = 0; index < size;) { |
571 |
| - const char* const ptr = (((char*) items) + index); |
572 |
| - memcpy(&item, ptr, sizeof(item)); |
573 |
| - |
574 |
| - if (!(strcmp(item.d_name, ".") == 0 || strcmp(item.d_name, "..") == 0)) { |
575 |
| - close(fd); |
576 |
| - return 0; |
577 |
| - } |
578 |
| - |
579 |
| - index += directory_entry_size(&item); |
580 |
| - } |
581 |
| - } |
582 |
| - #endif |
583 |
| - |
584 |
| - return 1; |
585 |
| - #endif |
586 |
| - |
587 |
| -} |
588 |
| - |
589 | 464 | int file_exists(const char* const filename) {
|
590 | 465 | /*
|
591 | 466 | Checks if file exists and is a regular file or symlink.
|
|
0 commit comments