File: bindc_12.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (28 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
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
program bindc_12
    use, intrinsic :: iso_c_binding, only : c_char, c_int, c_null_char
    implicit none

    interface
        function c_chdir(path) bind(C, name="chdir") result(stat)
            import :: c_char, c_int
            character(kind=c_char, len=1), intent(in) :: path(*)
            integer(c_int) :: stat
        end function c_chdir
    end interface

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

    allocate(cpath(5))
    cpath = [ '/', 't', 'm', 'p', c_null_char ]

    if (cpath(5) /= c_null_char) then
        error stop "C string not NUL terminated"
    end if
    stat = c_chdir(cpath)
    if (stat /= 0) then
        error stop "chdir failed"
    end if

    print *, "OK: chdir(/tmp) succeeded"
end program bindc_12