Hi all,
Depending on the filesystem, I’d like to call the C function realpath
(Unix) or _fullpath
(Windows). However, these two functions have a different set of parameters.
This works on Unix:
function realpath(path, resolved_path) result(ptr) &
bind(C, name="realpath")
import :: c_ptr, c_char
character(kind=c_char, len=1), intent(in) :: path(*)
character(kind=c_char, len=1), intent(out) :: resolved_path(*)
type(c_ptr) :: ptr
end function realpath
And this works on Windows:
function fullpath(resolved_path, path, maxLength) result(ptr) &
bind(C, name="_fullpath")
import :: c_ptr, c_char, c_int
character(kind=c_char, len=1), intent(out) :: resolved_path(*)
character(kind=c_char, len=1), intent(in) :: path(*)
integer(c_int), value, intent(in) :: maxLength
type(c_ptr) :: ptr
end function fullpath
Typically, I guess I’d do sth like:
function realpath(path, resolved_path) result(ptr) &
#ifndef _WIN32
bind(C, name="realpath")
#else
bind(C, name="_fullpath")
#endif
...
But this doesn’t work with a different set of arguments, right? Does anyone have an idea on how to solve it without defining two different functions that are called from code depending on the filesystem (that doesn’t work). To me this looks like
realpath
should be overloaded, but I’m not sure how this looks like when it’s bound to a C function.