diff options
author | Carlos Une <brocolis@eml.cc> | 2021-07-07 00:38:31 -0300 |
---|---|---|
committer | Carlos Une <brocolis@eml.cc> | 2021-07-07 00:38:31 -0300 |
commit | db869aa38ad7736df9eec5dfb8ac05b4ba45590b (patch) | |
tree | bdbf95df35ee864367c4c0ca8809a150c0ab5db4 /src/fpm_strings.f90 | |
parent | 7de24a6cf2a8bb13eda0a9921c6c5f9062fe159c (diff) | |
download | fpm-db869aa38ad7736df9eec5dfb8ac05b4ba45590b.tar.gz fpm-db869aa38ad7736df9eec5dfb8ac05b4ba45590b.zip |
Add C wrapper for file listing
Diffstat (limited to 'src/fpm_strings.f90')
-rw-r--r-- | src/fpm_strings.f90 | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/fpm_strings.f90 b/src/fpm_strings.f90 index 3d7d7b1..5a47311 100644 --- a/src/fpm_strings.f90 +++ b/src/fpm_strings.f90 @@ -29,6 +29,7 @@ module fpm_strings use iso_fortran_env, only: int64 +use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer, c_size_t implicit none private @@ -70,6 +71,10 @@ interface string_t module procedure new_string_t end interface string_t +interface f_string + module procedure f_string, f_string_cptr, f_string_cptr_n +end interface f_string + contains !> test if a CHARACTER string ends with a specified suffix @@ -125,6 +130,33 @@ function f_string(c_string) end function f_string +!> return Fortran character variable when given a null-terminated c_ptr +function f_string_cptr(cptr) result(s) + type(c_ptr), intent(in), value :: cptr + character(len=:,kind=c_char), allocatable :: s + + interface + function c_strlen(s) result(r) bind(c, name="strlen") + import c_size_t, c_ptr + type(c_ptr), intent(in), value :: s + integer(kind=c_size_t) :: r + end function + end interface + + s = f_string_cptr_n(cptr, c_strlen(cptr)) +end function + +!> return Fortran character variable when given a null-terminated c_ptr and its length +function f_string_cptr_n(cptr, n) result(s) + type(c_ptr), intent(in), value :: cptr + integer(kind=c_size_t), intent(in) :: n + character(len=n,kind=c_char) :: s + character(len=n,kind=c_char), pointer :: sptr + + call c_f_pointer(cptr, sptr) + s = sptr +end function + !> Hash a character(*) string of default kind pure function fnv_1a_char(input, seed) result(hash) character(*), intent(in) :: input |