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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module m_unzip
implicit none
interface
function unzip_file_c(archive, directory, indexed) bind(c, name="unzip_file")
use iso_c_binding
integer(kind=c_int)::unzip_file_c
type(c_ptr), value::archive, directory, indexed
end function unzip_file_c
end interface
contains
function unzip(archive, directory, indexed)
use iso_c_binding
implicit none
logical::unzip
character(*), intent(in)::archive, directory
character(*), intent(in), optional::indexed
character(kind=c_char, len=:), pointer::c_arc, c_dir, c_index
allocate(character(len=(len_trim(archive)+1)) :: c_arc)
c_arc = trim(archive)//c_null_char
allocate(character(len=(len_trim(directory)+1)) :: c_dir)
c_dir = trim(directory)//c_null_char
if(present(indexed)) then
allocate(character(len=(len_trim(indexed)+1)) :: c_index)
c_index = trim(indexed)//c_null_char
else
c_index => NULL()
end if
!if(associated(c_index)) then
unzip = (unzip_file_c(c_loc(c_arc), c_loc(c_dir), c_loc(c_index)) == 1)
deallocate(c_arc)
deallocate(c_dir)
if(associated(c_index)) then
deallocate(c_index)
end if
end function unzip
end module m_unzip
|