/* * Copyright (c) 2023 joshua stein * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __ZIP_H__ #define __ZIP_H__ #include "puff.h" #include "util.h" #define GET_U16(buf) (u_int16_t)(\ ((u_int16_t)((unsigned char *)buf)[1] << 8) | \ ((u_int16_t)((unsigned char *)buf)[0])) #define PUT_U16(buf, i) \ ((unsigned char *)buf)[0] = (i) & 0xff; \ ((unsigned char *)buf)[1] = ((i) >> 8) & 0xff; #define GET_U32(buf) (u_int32_t)(\ ((u_int32_t)((unsigned char *)buf)[3] << 24) | \ ((u_int32_t)((unsigned char *)buf)[2] << 16) | \ ((u_int32_t)((unsigned char *)buf)[1] << 8) | \ ((u_int32_t)((unsigned char *)buf)[0])) #define PUT_U32(buf, i) \ ((unsigned char *)buf)[0] = (i) & 0xff; \ ((unsigned char *)buf)[1] = ((i) >> 8) & 0xff; \ ((unsigned char *)buf)[2] = ((i) >> 16) & 0xff; \ ((unsigned char *)buf)[3] = ((i) >> 24) & 0xff; #define ZIP_OK 0 #define ZIP_BAD_FILE -1 #define ZIP_FAILED_OPEN -2 #define ZIP_SHORT_READ -3 #define ZIP_UNSUPPORTED -4 #define ZIP_NO_MEMORY -10 typedef bool zip_extract_decider(char *filename, size_t extracted_size); typedef void zip_extract_processor(char *filename, unsigned char *extracted_data, size_t extracted_size); bool zip_is_zip_file(Str255 path); short zip_read_file(Str255 path, zip_extract_decider *decider, zip_extract_processor *processor); #endif