Use common defines instead of static variables to check source supports all required operations.
Also, always mark ZIP_SOURCE_SUPPORTS as supported.
Fixes issue #289.
diff --git a/THANKS b/THANKS
index 89cc524..53f985e 100644
--- a/THANKS
+++ b/THANKS
@@ -41,6 +41,7 @@
Erwin Haid <erwin.haid@gmx.de>
Eun-cheol Joo
Fabrice Fontaine
+Filip Niksic
Florian Delizy <florian.delizy@gmail.com>
Force Charlie <charlieio@outlook.com>
François Simon <AT.GFI.Francois.SIMON@sesam-vitale.fr>
diff --git a/lib/zip_open.c b/lib/zip_open.c
index 1d2f69a..59b8238 100644
--- a/lib/zip_open.c
+++ b/lib/zip_open.c
@@ -77,9 +77,6 @@
ZIP_EXTERN zip_t *
zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
- static zip_int64_t needed_support_read = -1;
- static zip_int64_t needed_support_write = -1;
-
unsigned int flags;
zip_int64_t supported;
exists_t exists;
@@ -91,15 +88,11 @@
flags = (unsigned int)_flags;
supported = zip_source_supports(src);
- if (needed_support_read == -1) {
- needed_support_read = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_STAT, -1);
- needed_support_write = zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, -1);
- }
- if ((supported & needed_support_read) != needed_support_read) {
+ if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
return NULL;
}
- if ((supported & needed_support_write) != needed_support_write) {
+ if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
flags |= ZIP_RDONLY;
}
diff --git a/lib/zip_source_function.c b/lib/zip_source_function.c
index 44db947..ea22405 100644
--- a/lib/zip_source_function.c
+++ b/lib/zip_source_function.c
@@ -57,7 +57,7 @@
zs->cb.f = zcb;
zs->ud = ud;
- zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS);
+ zs->supports = zcb(ud, NULL, 0, ZIP_SOURCE_SUPPORTS) | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, -1);
if (zs->supports < 0) {
zs->supports = ZIP_SOURCE_SUPPORTS_READABLE;
}