1 /* Copyright 2015 the unarr project authors (see AUTHORS file). 2 License: LGPLv3 */ 3 4 /* this is the common private/implementation API of unarr which should only be used by unarr code */ 5 6 #ifndef common_unarr_imp_h 7 #define common_unarr_imp_h 8 9 #include "../unarr.h" 10 #include "allocator.h" 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <stdarg.h> 15 #include <string.h> 16 #include <inttypes.h> 17 18 /***** conv ****/ 19 20 size_t ar_conv_rune_to_utf8(wchar_t rune, char *out, size_t size); 21 char *ar_conv_dos_to_utf8(const char *astr); 22 time64_t ar_conv_dosdate_to_filetime(uint32_t dosdate); 23 24 /***** crc32 *****/ 25 26 uint32_t ar_crc32(uint32_t crc32, const unsigned char *data, size_t data_len); 27 28 /***** stream *****/ 29 30 typedef void (* ar_stream_close_fn)(void *data); 31 typedef size_t (* ar_stream_read_fn)(void *data, void *buffer, size_t count); 32 typedef bool (* ar_stream_seek_fn)(void *data, off64_t offset, int origin); 33 typedef off64_t (* ar_stream_tell_fn)(void *data); 34 35 struct ar_stream_s { 36 ar_stream_close_fn close; 37 ar_stream_read_fn read; 38 ar_stream_seek_fn seek; 39 ar_stream_tell_fn tell; 40 void *data; 41 }; 42 43 ar_stream *ar_open_stream(void *data, ar_stream_close_fn close, ar_stream_read_fn read, ar_stream_seek_fn seek, ar_stream_tell_fn tell); 44 45 /***** unarr *****/ 46 47 #define warn(...) ar_log("!", __FILE__, __LINE__, __VA_ARGS__) 48 #ifndef NDEBUG 49 #define log(...) ar_log("-", __FILE__, __LINE__, __VA_ARGS__) 50 #else 51 #define log(...) ((void)0) 52 #endif 53 void ar_log(const char *prefix, const char *file, int line, const char *msg, ...); 54 55 typedef void (* ar_archive_close_fn)(ar_archive *ar); 56 typedef bool (* ar_parse_entry_fn)(ar_archive *ar, off64_t offset); 57 typedef const char *(* ar_entry_get_name_fn)(ar_archive *ar); 58 typedef bool (* ar_entry_uncompress_fn)(ar_archive *ar, void *buffer, size_t count); 59 typedef size_t (* ar_get_global_comment_fn)(ar_archive *ar, void *buffer, size_t count); 60 61 struct ar_archive_s { 62 ar_archive_close_fn close; 63 ar_parse_entry_fn parse_entry; 64 ar_entry_get_name_fn get_name; 65 ar_entry_uncompress_fn uncompress; 66 ar_get_global_comment_fn get_comment; 67 68 ar_stream *stream; 69 bool at_eof; 70 off64_t entry_offset; 71 off64_t entry_offset_first; 72 off64_t entry_offset_next; 73 size_t entry_size_uncompressed; 74 time64_t entry_filetime; 75 }; 76 77 ar_archive *ar_open_archive(ar_stream *stream, size_t struct_size, ar_archive_close_fn close, ar_parse_entry_fn parse_entry, 78 ar_entry_get_name_fn get_name, ar_entry_uncompress_fn uncompress, ar_get_global_comment_fn get_comment, 79 off64_t first_entry_offset); 80 81 #endif 82