f_string_to_c_ptr Subroutine

private subroutine f_string_to_c_ptr(fstr, buffer)

Convert a Fortran string to a c_ptr to a string. (the C string must already have been allocated to a fixed size)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fstr
type(c_ptr), intent(inout) :: buffer

a preallocated string buffer


Calls

proc~~f_string_to_c_ptr~~CallsGraph proc~f_string_to_c_ptr c_interface_module::f_string_to_c_ptr interface~strlen c_interface_module::strlen proc~f_string_to_c_ptr->interface~strlen s s proc~f_string_to_c_ptr->s

Called by

proc~~f_string_to_c_ptr~~CalledByGraph proc~f_string_to_c_ptr c_interface_module::f_string_to_c_ptr proc~return_a_string c_interface_module::return_a_string proc~return_a_string->proc~f_string_to_c_ptr

Source Code

    subroutine f_string_to_c_ptr(fstr,buffer)

    implicit none

    character(len=*),intent(in) :: fstr
    type(c_ptr),intent(inout) :: buffer   !! a preallocated string buffer

    integer :: ilen !! string length of buffer

    ilen = strlen(buffer)

    block
        character(kind=c_char,len=ilen+1),pointer :: s
        call c_f_pointer(buffer,s)
        s(1:min(len(fstr),ilen)) = fstr(1:min(len(fstr),ilen))
        buffer = c_loc(s)
    end block

    end subroutine f_string_to_c_ptr