11
!! Until we set F2008 as the reference, this is needed for F2003
13
subroutine system(str,stat)
14
use iso_c_binding, only: C_CHAR, C_NULL_CHAR, C_INT
16
character(len=*), intent(in) :: str
17
integer, intent(out), optional :: stat
19
integer(c_int) function c_system(string) bind(C,name="system")
20
use iso_c_binding, only: c_char, c_int
21
character(kind=c_char) :: string(*)
25
integer(C_INT) :: return_value
27
return_value = c_system(str // C_NULL_CHAR)
28
if (present(stat)) then
34
!-----------------------------------------------------
35
subroutine chdir(path, stat)
36
use iso_c_binding, only: C_CHAR, C_NULL_CHAR, C_INT
40
integer, optional, intent(out) :: stat
42
integer(C_INT) :: return_value
45
integer(c_int) function c_chdir(path) bind(C,name="chdir")
46
use iso_c_binding, only: c_char, c_int
47
character(kind=c_char) :: path(*)
51
return_value = c_chdir(path//c_null_char)
53
if (present(stat)) then
57
!--------------------------------------------------
59
! If 'path' is too short to hold the result, stat will be "1".
61
! You *should* use the stat argument!
63
subroutine getcwd(path, stat)
64
use iso_c_binding, only: C_CHAR, C_INT, C_ASSOCIATED, C_PTR, C_SIZE_T
66
character(len=*), intent(out) :: path
67
integer, optional, intent(out) :: stat
70
! char * getcwd(char *buf, size_t size);
72
function c_getcwd(str,str_size) result(res) bind(C, name="getcwd")
73
use ISO_C_Binding, only: C_CHAR, C_PTR, C_SIZE_T
74
character(kind=C_CHAR),intent(out) :: str(*)
75
integer(kind=C_SIZE_T),intent(in), VALUE :: str_size
80
integer(C_INT) :: return_value
83
integer(kind=C_SIZE_T) :: str_size
84
type(c_PTR) :: p_result
87
p_result = c_getcwd(path,str_size)
89
if (c_associated(p_result)) then
90
! Remove stuff past the null-character
91
null_loc = index( path, char(0) )
92
path = path(1:null_loc-1)
99
if (present(stat)) then
103
end subroutine getcwd
106
!!! https://stackoverflow.com/questions/30279228/is-there-an-alternative-to-getcwd-in-fortran-2003-2008
107
!!! for "Windows" code
110
end module posix_calls