| 34 | } |
| 35 | |
| 36 | static inline std::unique_ptr<zip_t, void (*)(zip_t*)> zip_open_buffer_managed(const void* buffer, size_t size, int flags, int freep, zip_error_t* ze) |
| 37 | { |
| 38 | zip_source_t* zs = zip_source_buffer_create(buffer, size, freep, ze); |
| 39 | zip_t* zip = nullptr; |
| 40 | if (zs && !(zip = zip_open_from_source(zs, flags, ze))) |
| 41 | { |
| 42 | // have to clean up source |
| 43 | zip_source_free(zs); |
| 44 | } |
| 45 | |
| 46 | return std::unique_ptr<zip_t, void (*)(zip_t*)>(zip, [](zip_t* zf) { |
| 47 | if (!zf) |
| 48 | return; |
| 49 | |
| 50 | int err = zip_close(zf); |
| 51 | if (err != 0) |
| 52 | { |
| 53 | Console.Error("Failed to close zip file: %d", err); |
| 54 | zip_discard(zf); |
| 55 | } |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | static inline std::unique_ptr<zip_file_t, int (*)(zip_file_t*)> zip_fopen_managed(zip_t* zip, const char* filename, zip_flags_t flags) |
| 60 | { |
nothing calls this directly
no test coverage detected