make_c_string Subroutine

private subroutine make_c_string(txt, buf, pos, ptr, len_out)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: txt
character(kind=c_char, len=1), intent(inout), target :: buf(:)
integer, intent(inout) :: pos
type(c_ptr), intent(out) :: ptr
integer(kind=c_int), intent(out) :: len_out

Called by

proc~~make_c_string~~CalledByGraph proc~make_c_string make_c_string proc~expose_state_to_ext_library expose_state_to_ext_library proc~expose_state_to_ext_library->proc~make_c_string

Source Code

subroutine make_c_string(txt, buf, pos, ptr, len_out)
    character(*), intent(in)                         :: txt
    character(kind=c_char), intent(inout), target    :: buf(:)
    integer,               intent(inout)             :: pos
    type(c_ptr),           intent(out)               :: ptr
    integer(c_int),        intent(out)               :: len_out

    integer :: L, i, start

    L     = len(txt)
    start = pos

    if (start + L > size(buf)) then
        error stop 'make_c_string: buffer too small'
    end if

    do i = 1, L
        buf(start + i - 1) = txt(i:i)
    end do
    buf(start + L) = c_null_char

    ptr     = c_loc(buf(start))
    len_out = L + 1
    pos     = start + L + 1
end subroutine make_c_string