|
1 | 1 | module stdlib_system |
2 | 2 | use, intrinsic :: iso_c_binding, only : c_int, c_long, c_null_ptr, c_int64_t |
3 | | -use stdlib_kinds, only: int64, dp |
| 3 | +use stdlib_kinds, only: int64, dp, c_bool, c_char |
| 4 | +use stdlib_strings, only: to_c_char |
4 | 5 | implicit none |
5 | 6 | private |
6 | 7 | public :: sleep |
@@ -81,6 +82,22 @@ module stdlib_system |
81 | 82 | public :: elapsed |
82 | 83 | public :: is_windows |
83 | 84 |
|
| 85 | +!! version: experimental |
| 86 | +!! |
| 87 | +!! Tests if a given path matches an existing directory. |
| 88 | +!! ([Specification](../page/specs/stdlib_io.html#is_directory-test-if-a-path-is-a-directory)) |
| 89 | +!! |
| 90 | +!!### Summary |
| 91 | +!! Function to evaluate whether a specified path corresponds to an existing directory. |
| 92 | +!! |
| 93 | +!!### Description |
| 94 | +!! |
| 95 | +!! This function checks if a given file system path is a directory. It is cross-platform and avoids reliance |
| 96 | +!! on external C libraries by utilizing system calls. It supports common operating systems such as Linux, macOS, |
| 97 | +!! Windows, and various UNIX-like environments. On unsupported operating systems, the function will return `.false.`. |
| 98 | +!! |
| 99 | +public :: is_directory |
| 100 | + |
84 | 101 | ! CPU clock ticks storage |
85 | 102 | integer, parameter, private :: TICKS = int64 |
86 | 103 | integer, parameter, private :: RTICKS = dp |
@@ -618,4 +635,23 @@ pure function OS_NAME(os) |
618 | 635 | end select |
619 | 636 | end function OS_NAME |
620 | 637 |
|
| 638 | +!! Tests if a given path matches an existing directory. |
| 639 | +!! Cross-platform implementation without using external C libraries. |
| 640 | +logical function is_directory(path) |
| 641 | + !> Input path to evaluate |
| 642 | + character(*), intent(in) :: path |
| 643 | + |
| 644 | + interface |
| 645 | + |
| 646 | + logical(c_bool) function stdlib_is_directory(path) bind(c, name="stdlib_is_directory") |
| 647 | + import c_bool, c_char |
| 648 | + character(kind=c_char), intent(in) :: path(*) |
| 649 | + end function stdlib_is_directory |
| 650 | + |
| 651 | + end interface |
| 652 | + |
| 653 | + is_directory = logical(stdlib_is_directory(to_c_char(path))) |
| 654 | + |
| 655 | +end function is_directory |
| 656 | + |
621 | 657 | end module stdlib_system |
0 commit comments