The current working directory, or . if it cannot be determined.
function current_directory() result(path) !! The current working directory, or `.` if it cannot be determined. character(len=:), allocatable :: path character(kind=c_char), allocatable :: buf(:) integer :: n allocate (buf(4096)) if (.not. c_associated(c_getcwd(buf, int(size(buf), c_size_t)))) then path = '.' return end if n = 0 do while (n < size(buf)) if (buf(n + 1) == c_null_char) exit n = n + 1 end do allocate (character(len=n) :: path) path = transfer(buf(1:n), path) end function current_directory