File indexing completed on 2025-02-02 04:25:58

0001 /* Copyright 2015 the unarr project authors (see AUTHORS file).
0002    License: LGPLv3 */
0003 
0004 /* this is the common private/implementation API of unarr which should only be used by unarr code */
0005 
0006 #ifndef common_unarr_imp_h
0007 #define common_unarr_imp_h
0008 
0009 #include "../unarr.h"
0010 #include "allocator.h"
0011 
0012 #include <stdlib.h>
0013 #include <stdio.h>
0014 #include <stdarg.h>
0015 #include <string.h>
0016 #include <inttypes.h>
0017 
0018 /***** conv ****/
0019 
0020 size_t ar_conv_rune_to_utf8(wchar_t rune, char *out, size_t size);
0021 char *ar_conv_dos_to_utf8(const char *astr);
0022 time64_t ar_conv_dosdate_to_filetime(uint32_t dosdate);
0023 
0024 /***** crc32 *****/
0025 
0026 uint32_t ar_crc32(uint32_t crc32, const unsigned char *data, size_t data_len);
0027 
0028 /***** stream *****/
0029 
0030 typedef void (* ar_stream_close_fn)(void *data);
0031 typedef size_t (* ar_stream_read_fn)(void *data, void *buffer, size_t count);
0032 typedef bool (* ar_stream_seek_fn)(void *data, off64_t offset, int origin);
0033 typedef off64_t (* ar_stream_tell_fn)(void *data);
0034 
0035 struct ar_stream_s {
0036     ar_stream_close_fn close;
0037     ar_stream_read_fn read;
0038     ar_stream_seek_fn seek;
0039     ar_stream_tell_fn tell;
0040     void *data;
0041 };
0042 
0043 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);
0044 
0045 /***** unarr *****/
0046 
0047 #define warn(...) ar_log("!", __FILE__, __LINE__, __VA_ARGS__)
0048 #ifndef NDEBUG
0049 #define log(...) ar_log("-", __FILE__, __LINE__, __VA_ARGS__)
0050 #else
0051 #define log(...) ((void)0)
0052 #endif
0053 void ar_log(const char *prefix, const char *file, int line, const char *msg, ...);
0054 
0055 typedef void (* ar_archive_close_fn)(ar_archive *ar);
0056 typedef bool (* ar_parse_entry_fn)(ar_archive *ar, off64_t offset);
0057 typedef const char *(* ar_entry_get_name_fn)(ar_archive *ar);
0058 typedef bool (* ar_entry_uncompress_fn)(ar_archive *ar, void *buffer, size_t count);
0059 typedef size_t (* ar_get_global_comment_fn)(ar_archive *ar, void *buffer, size_t count);
0060 
0061 struct ar_archive_s {
0062     ar_archive_close_fn close;
0063     ar_parse_entry_fn parse_entry;
0064     ar_entry_get_name_fn get_name;
0065     ar_entry_uncompress_fn uncompress;
0066     ar_get_global_comment_fn get_comment;
0067 
0068     ar_stream *stream;
0069     bool at_eof;
0070     off64_t entry_offset;
0071     off64_t entry_offset_first;
0072     off64_t entry_offset_next;
0073     size_t entry_size_uncompressed;
0074     time64_t entry_filetime;
0075 };
0076 
0077 ar_archive *ar_open_archive(ar_stream *stream, size_t struct_size, ar_archive_close_fn close, ar_parse_entry_fn parse_entry,
0078                             ar_entry_get_name_fn get_name, ar_entry_uncompress_fn uncompress, ar_get_global_comment_fn get_comment,
0079                             off64_t first_entry_offset);
0080 
0081 #endif