File: array12.f90

package info (click to toggle)
lfortran 0.58.0-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 54,508 kB
  • sloc: cpp: 162,179; f90: 68,251; python: 17,476; ansic: 6,278; yacc: 2,334; sh: 1,317; fortran: 892; makefile: 34; javascript: 15
file content (30 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module array12
    use, intrinsic :: iso_c_binding, only: c_char, c_int, c_ptr, c_associated
    implicit none

    interface
        function getcwd(buf, bufsize) result(path) bind(C, name="getcwd")
            import :: c_char, c_int, c_ptr
            character(kind=c_char, len=1), intent(in) :: buf(*)
            integer(c_int), value, intent(in) :: bufsize
            type(c_ptr) :: path
        end function getcwd
   end interface

contains

subroutine get_current_directory(path)
    character(len=:), allocatable, intent(out) :: path
    character(kind=c_char, len=1), allocatable :: cpath(:)
    integer(c_int), parameter :: buffersize = 1000_c_int
    type(c_ptr) :: tmp

    allocate(cpath(buffersize))

    tmp = getcwd(cpath, buffersize)
    if (c_associated(tmp)) then
       print *, "PWD: ", tmp
    end if
end subroutine get_current_directory

end module array12