diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-10-24 15:35:39 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-10-24 15:35:39 -0400 |
commit | 0f75ab0e3cea30ee86d2bd34cff125b221d5d02b (patch) | |
tree | 337832766d4b20d29229ce1766f3ffcc0987ca71 /unzip_wrap.f90 | |
download | libzip-wrapper-0f75ab0e3cea30ee86d2bd34cff125b221d5d02b.tar.gz libzip-wrapper-0f75ab0e3cea30ee86d2bd34cff125b221d5d02b.zip |
Initial code commit
Diffstat (limited to 'unzip_wrap.f90')
-rw-r--r-- | unzip_wrap.f90 | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/unzip_wrap.f90 b/unzip_wrap.f90 new file mode 100644 index 0000000..c29dfd7 --- /dev/null +++ b/unzip_wrap.f90 @@ -0,0 +1,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
\ No newline at end of file |