get_current_directory Subroutine

public subroutine get_current_directory(path, error)

Arguments

Type IntentOptional Attributes Name
character(len=:), intent(out), allocatable :: path
type(error_t), intent(out), allocatable :: error

Source Code

    subroutine get_current_directory(path, error)
        character(len=:), allocatable, intent(out) :: path
        type(error_t), allocatable, intent(out) :: error

        character(kind=c_char, len=1), allocatable :: cpath(:)
        type(c_ptr) :: tmp

        allocate (cpath(buffersize))

        tmp = getcwd_(cpath, buffersize)
        if (c_associated(tmp)) then
            call c_f_character(cpath, path)
        else
            call fatal_error(error, "Failed to retrieve current directory")
        end if

    end subroutine get_current_directory