Download
jcs
/subtext
/zip.h
(View History)
jcs zip: Make zip_read_file return an error code depending on failure | Latest amendment: 455 on 2023-03-27 |
1 | /* |
2 | * Copyright (c) 2023 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __ZIP_H__ |
18 | #define __ZIP_H__ |
19 | |
20 | #include "puff.h" |
21 | #include "util.h" |
22 | |
23 | #define GET_U16(buf) (u_int16_t)(\ |
24 | ((u_int16_t)((unsigned char *)buf)[1] << 8) | \ |
25 | ((u_int16_t)((unsigned char *)buf)[0])) |
26 | #define PUT_U16(buf, i) \ |
27 | ((unsigned char *)buf)[0] = (i) & 0xff; \ |
28 | ((unsigned char *)buf)[1] = ((i) >> 8) & 0xff; |
29 | #define GET_U32(buf) (u_int32_t)(\ |
30 | ((u_int32_t)((unsigned char *)buf)[3] << 24) | \ |
31 | ((u_int32_t)((unsigned char *)buf)[2] << 16) | \ |
32 | ((u_int32_t)((unsigned char *)buf)[1] << 8) | \ |
33 | ((u_int32_t)((unsigned char *)buf)[0])) |
34 | #define PUT_U32(buf, i) \ |
35 | ((unsigned char *)buf)[0] = (i) & 0xff; \ |
36 | ((unsigned char *)buf)[1] = ((i) >> 8) & 0xff; \ |
37 | ((unsigned char *)buf)[2] = ((i) >> 16) & 0xff; \ |
38 | ((unsigned char *)buf)[3] = ((i) >> 24) & 0xff; |
39 | |
40 | #define ZIP_OK 0 |
41 | #define ZIP_BAD_FILE -1 |
42 | #define ZIP_FAILED_OPEN -2 |
43 | #define ZIP_SHORT_READ -3 |
44 | #define ZIP_UNSUPPORTED -4 |
45 | #define ZIP_NO_MEMORY -10 |
46 | |
47 | typedef bool zip_extract_decider(char *filename, size_t extracted_size); |
48 | typedef void zip_extract_processor(char *filename, |
49 | unsigned char *extracted_data, size_t extracted_size); |
50 | |
51 | bool zip_is_zip_file(Str255 path); |
52 | short zip_read_file(Str255 path, zip_extract_decider *decider, |
53 | zip_extract_processor *processor); |
54 | |
55 | #endif |