change_directory Subroutine

public subroutine change_directory(path, error)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: path
type(error_t), intent(out), allocatable:: error

Contents

Source Code


Variables

TypeVisibility AttributesNameInitial
character(kind=c_char,len=1), public, allocatable:: cpath(:)
integer, public :: stat

Source Code

    subroutine change_directory(path, error)
        character(len=*), intent(in) :: path
        type(error_t), allocatable, intent(out) :: error

        character(kind=c_char, len=1), allocatable :: cpath(:)
        integer :: stat

        allocate(cpath(len(path)+1))
        call f_c_character(path, cpath, len(path)+1)

        stat = chdir(cpath)

        if (stat /= 0) then
            call fatal_error(error, "Failed to change directory to '"//path//"'")
        end if
    end subroutine change_directory