Harmonize gmio_adv_encode_xxx() API functions
This commit is contained in:
parent
1c80b326ee
commit
f1a6bf764c
@ -82,16 +82,16 @@ GMIO_INLINE uint16_t gmio_adv_decode_uint16_le(const uint8_t** bytes);
|
||||
GMIO_INLINE uint16_t gmio_adv_decode_uint16_be(const uint8_t** bytes);
|
||||
GMIO_INLINE uint32_t gmio_adv_decode_uint32_le(const uint8_t** bytes);
|
||||
GMIO_INLINE uint32_t gmio_adv_decode_uint32_be(const uint8_t** bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint16_le(uint16_t val, uint8_t* bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint16_be(uint16_t val, uint8_t* bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint32_le(uint32_t val, uint8_t* bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint32_be(uint32_t val, uint8_t* bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint16_le(uint16_t val, uint8_t** bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint16_be(uint16_t val, uint8_t** bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint32_le(uint32_t val, uint8_t** bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint32_be(uint32_t val, uint8_t** bytes);
|
||||
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
GMIO_INLINE uint64_t gmio_adv_decode_uint64_le(const uint8_t** bytes);
|
||||
GMIO_INLINE uint64_t gmio_adv_decode_uint64_be(const uint8_t** bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint64_le(uint64_t val, uint8_t* bytes);
|
||||
GMIO_INLINE uint8_t* gmio_adv_encode_uint64_be(uint64_t val, uint8_t* bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint64_le(uint64_t val, uint8_t** bytes);
|
||||
GMIO_INLINE void gmio_adv_encode_uint64_be(uint64_t val, uint8_t** bytes);
|
||||
#endif /* GMIO_HAVE_INT64_TYPE */
|
||||
|
||||
|
||||
@ -222,28 +222,28 @@ uint32_t gmio_adv_decode_uint32_be(const uint8_t** bytes)
|
||||
return val;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint16_le(uint16_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint16_le(uint16_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint16_le(val, bytes);
|
||||
return bytes + 2;
|
||||
gmio_encode_uint16_le(val, *bytes);
|
||||
*bytes += 2;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint16_be(uint16_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint16_be(uint16_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint16_be(val, bytes);
|
||||
return bytes + 2;
|
||||
gmio_encode_uint16_be(val, *bytes);
|
||||
*bytes += 2;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint32_le(uint32_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint32_le(uint32_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint32_le(val, bytes);
|
||||
return bytes + 4;
|
||||
gmio_encode_uint32_le(val, *bytes);
|
||||
*bytes += 4;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint32_be(uint32_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint32_be(uint32_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint32_be(val, bytes);
|
||||
return bytes + 4;
|
||||
gmio_encode_uint32_be(val, *bytes);
|
||||
*bytes += 4;
|
||||
}
|
||||
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
@ -262,16 +262,16 @@ uint64_t gmio_adv_decode_uint64_be(const uint8_t** bytes)
|
||||
return val;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint64_le(uint64_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint64_le(uint64_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint64_le(val, bytes);
|
||||
return bytes + 8;
|
||||
gmio_encode_uint64_le(val, *bytes);
|
||||
*bytes += 8;
|
||||
}
|
||||
|
||||
uint8_t* gmio_adv_encode_uint64_be(uint64_t val, uint8_t* bytes)
|
||||
void gmio_adv_encode_uint64_be(uint64_t val, uint8_t** bytes)
|
||||
{
|
||||
gmio_encode_uint64_be(val, bytes);
|
||||
return bytes + 8;
|
||||
gmio_encode_uint64_be(val, *bytes);
|
||||
*bytes += 8;
|
||||
}
|
||||
|
||||
#endif /* GMIO_HAVE_INT64_TYPE */
|
||||
|
@ -112,40 +112,30 @@ size_t gmio_zip_read_local_file_header(
|
||||
struct gmio_zip_local_file_header *info,
|
||||
int *ptr_error)
|
||||
{
|
||||
uint8_t buff[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER];
|
||||
const uint8_t* buffit = buff;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER];
|
||||
const uint8_t* buff = bytes;
|
||||
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, bytes, sizeof(bytes));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(bytes)))
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_STREAM, ptr_error);
|
||||
|
||||
/* 4-bytes magic */
|
||||
if (gmio_adv_decode_uint32_le(&buffit) != 0x04034b50) {
|
||||
if (gmio_adv_decode_uint32_le(&buff) != 0x04034b50) {
|
||||
return gmio_zip_io_returnerr(
|
||||
read_len, GMIO_ZIP_UTILS_ERROR_BAD_MAGIC, ptr_error);
|
||||
}
|
||||
/* 2-bytes version needed to extract */
|
||||
info->version_needed_to_extract = gmio_adv_decode_uint16_le(&buffit);
|
||||
/* 2-bytes general purpose bit flag */
|
||||
info->general_purpose_flags = gmio_adv_decode_uint16_le(&buffit);
|
||||
/* 2-bytes compression method */
|
||||
info->compress_method = gmio_adv_decode_uint16_le(&buffit);
|
||||
/* 2-bytes last mod file time */
|
||||
/* 2-bytes last mod file date */
|
||||
info->version_needed_to_extract = gmio_adv_decode_uint16_le(&buff);
|
||||
info->general_purpose_flags = gmio_adv_decode_uint16_le(&buff);
|
||||
info->compress_method = gmio_adv_decode_uint16_le(&buff);
|
||||
/* 2-bytes last mod file time + 2-bytes last mod file date */
|
||||
/* TODO: convert DOS datetime to struct tm */
|
||||
const uint32_t dos_datetime = gmio_adv_decode_uint32_le(&buffit);
|
||||
const uint32_t dos_datetime = gmio_adv_decode_uint32_le(&buff);
|
||||
GMIO_UNUSED(dos_datetime);
|
||||
info->lastmod_datetime = NULL;
|
||||
/* 4-bytes crc-32 */
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buffit);
|
||||
/* 4-bytes compressed size */
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
/* 4-bytes uncompressed size */
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
/* 2-bytes file name length */
|
||||
info->filename_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
/* 2-bytes extra field length */
|
||||
info->extrafield_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buff);
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->filename_len = gmio_adv_decode_uint16_le(&buff);
|
||||
info->extrafield_len = gmio_adv_decode_uint16_le(&buff);
|
||||
|
||||
info->filename = NULL;
|
||||
info->extrafield = NULL;
|
||||
@ -158,20 +148,20 @@ size_t gmio_zip_write_data_descriptor(
|
||||
const struct gmio_zip_data_descriptor *info,
|
||||
int* ptr_error)
|
||||
{
|
||||
const size_t fixed_data_len =
|
||||
const size_t bytes_len =
|
||||
info->use_zip64 ?
|
||||
GMIO_ZIP64_SIZE_DATA_DESCRIPTOR :
|
||||
GMIO_ZIP_SIZE_DATA_DESCRIPTOR;
|
||||
uint8_t fixed_data[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR];
|
||||
uint8_t* buff = fixed_data;
|
||||
uint8_t bytes[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR];
|
||||
uint8_t* buff = bytes;
|
||||
|
||||
/* 4-bytes crc-32 */
|
||||
buff = gmio_adv_encode_uint32_le(info->crc32, buff);
|
||||
gmio_adv_encode_uint32_le(info->crc32, &buff);
|
||||
/* Compressed size and uncompressed size (4 or 8 bytes) */
|
||||
if (info->use_zip64) {
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
buff = gmio_adv_encode_uint64_le(info->compressed_size, buff);
|
||||
buff = gmio_adv_encode_uint64_le(info->uncompressed_size, buff);
|
||||
gmio_adv_encode_uint64_le(info->compressed_size, &buff);
|
||||
gmio_adv_encode_uint64_le(info->uncompressed_size, &buff);
|
||||
#else
|
||||
/* TODO: error code */
|
||||
return gmio_zip_io_returnerr(0, GMIO_ERROR_UNKNOWN, ptr_error);
|
||||
@ -181,8 +171,8 @@ size_t gmio_zip_write_data_descriptor(
|
||||
if (info->compressed_size <= UINT32_MAX
|
||||
&& info->uncompressed_size <= UINT32_MAX)
|
||||
{
|
||||
buff = gmio_adv_encode_uint32_le((uint32_t)info->compressed_size, buff);
|
||||
buff = gmio_adv_encode_uint32_le((uint32_t)info->uncompressed_size, buff);
|
||||
gmio_adv_encode_uint32_le((uint32_t)info->compressed_size, &buff);
|
||||
gmio_adv_encode_uint32_le((uint32_t)info->uncompressed_size, &buff);
|
||||
}
|
||||
else {
|
||||
/* TODO: error code */
|
||||
@ -192,9 +182,9 @@ size_t gmio_zip_write_data_descriptor(
|
||||
|
||||
/* Write to stream */
|
||||
const size_t written_len =
|
||||
gmio_stream_write_bytes(stream, fixed_data, fixed_data_len);
|
||||
gmio_stream_write_bytes(stream, bytes, bytes_len);
|
||||
return gmio_zip_write_returnhelper(
|
||||
stream, written_len, fixed_data_len, ptr_error);
|
||||
stream, written_len, bytes_len, ptr_error);
|
||||
}
|
||||
|
||||
size_t gmio_zip_read_central_directory_header(
|
||||
@ -202,38 +192,37 @@ size_t gmio_zip_read_central_directory_header(
|
||||
struct gmio_zip_central_directory_header *info,
|
||||
int *ptr_error)
|
||||
{
|
||||
uint8_t buff[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER];
|
||||
const uint8_t* buffit = buff;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER];
|
||||
const uint8_t* buff = bytes;
|
||||
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, bytes, sizeof(bytes));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(bytes)))
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_STREAM, ptr_error);
|
||||
|
||||
/* 4-bytes magic */
|
||||
if (gmio_adv_decode_uint32_le(&buffit) != 0x02014b50) {
|
||||
if (gmio_adv_decode_uint32_le(&buff) != 0x02014b50) {
|
||||
return gmio_zip_io_returnerr(
|
||||
read_len, GMIO_ZIP_UTILS_ERROR_BAD_MAGIC, ptr_error);
|
||||
}
|
||||
|
||||
info->version_made_by = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->version_needed_to_extract = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->general_purpose_flags = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->compress_method = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->version_made_by = gmio_adv_decode_uint16_le(&buff);
|
||||
info->version_needed_to_extract = gmio_adv_decode_uint16_le(&buff);
|
||||
info->general_purpose_flags = gmio_adv_decode_uint16_le(&buff);
|
||||
info->compress_method = gmio_adv_decode_uint16_le(&buff);
|
||||
/* 2-bytes last mod file time + 2-bytes last mod file date */
|
||||
/* TODO: convert DOS datetime to struct tm */
|
||||
const uint32_t dos_datetime = gmio_adv_decode_uint32_le(&buffit);
|
||||
const uint32_t dos_datetime = gmio_adv_decode_uint32_le(&buff);
|
||||
GMIO_UNUSED(dos_datetime);
|
||||
info->lastmod_datetime = NULL;
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->filename_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->extrafield_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->filecomment_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->disk_nb_start = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->internal_file_attrs = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->external_file_attrs = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->relative_offset_local_header = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buff);
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->filename_len = gmio_adv_decode_uint16_le(&buff);
|
||||
info->extrafield_len = gmio_adv_decode_uint16_le(&buff);
|
||||
info->filecomment_len = gmio_adv_decode_uint16_le(&buff);
|
||||
info->disk_nb_start = gmio_adv_decode_uint16_le(&buff);
|
||||
info->internal_file_attrs = gmio_adv_decode_uint16_le(&buff);
|
||||
info->external_file_attrs = gmio_adv_decode_uint32_le(&buff);
|
||||
info->relative_offset_local_header = gmio_adv_decode_uint32_le(&buff);
|
||||
|
||||
info->filename = NULL;
|
||||
info->extrafield = NULL;
|
||||
@ -247,28 +236,28 @@ size_t gmio_zip_read_end_of_central_directory_record(
|
||||
struct gmio_zip_end_of_central_directory_record *info,
|
||||
int *ptr_error)
|
||||
{
|
||||
uint8_t buff[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD];
|
||||
const uint8_t* buffit = buff;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD];
|
||||
const uint8_t* buff = bytes;
|
||||
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, bytes, sizeof(bytes));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(bytes)))
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_STREAM, ptr_error);
|
||||
|
||||
/* 4-bytes magic */
|
||||
if (gmio_adv_decode_uint32_le(&buffit) != 0x06054b50) {
|
||||
if (gmio_adv_decode_uint32_le(&buff) != 0x06054b50) {
|
||||
return gmio_zip_io_returnerr(
|
||||
read_len, GMIO_ZIP_UTILS_ERROR_BAD_MAGIC, ptr_error);
|
||||
}
|
||||
|
||||
info->disk_nb = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->disk_nb_with_start_of_central_dir = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->disk_nb = gmio_adv_decode_uint16_le(&buff);
|
||||
info->disk_nb_with_start_of_central_dir = gmio_adv_decode_uint16_le(&buff);
|
||||
info->total_entry_count_in_central_dir_on_disk =
|
||||
gmio_adv_decode_uint16_le(&buffit);
|
||||
info->total_entry_count_in_central_dir = gmio_adv_decode_uint16_le(&buffit);
|
||||
info->central_dir_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
gmio_adv_decode_uint16_le(&buff);
|
||||
info->total_entry_count_in_central_dir = gmio_adv_decode_uint16_le(&buff);
|
||||
info->central_dir_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->start_offset_central_dir_from_disk_start_nb =
|
||||
gmio_adv_decode_uint32_le(&buffit);
|
||||
info->filecomment_len = gmio_adv_decode_uint16_le(&buffit);
|
||||
gmio_adv_decode_uint32_le(&buff);
|
||||
info->filecomment_len = gmio_adv_decode_uint16_le(&buff);
|
||||
info->filecomment = NULL;
|
||||
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_OK, ptr_error);
|
||||
@ -279,35 +268,34 @@ size_t gmio_zip_write_local_file_header(
|
||||
const struct gmio_zip_local_file_header* info,
|
||||
int* ptr_error)
|
||||
{
|
||||
uint8_t fixed_data[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER];
|
||||
uint8_t* buff = fixed_data;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER];
|
||||
uint8_t* buff = bytes;
|
||||
|
||||
const bool use_data_descriptor =
|
||||
info->general_purpose_flags
|
||||
& GMIO_ZIP_GENERAL_PURPOSE_FLAG_USE_DATA_DESCRIPTOR;
|
||||
|
||||
buff = gmio_adv_encode_uint32_le(0x04034b50, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->version_needed_to_extract, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->general_purpose_flags, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->compress_method, buff);
|
||||
gmio_adv_encode_uint32_le(0x04034b50, &buff);
|
||||
gmio_adv_encode_uint16_le(info->version_needed_to_extract, &buff);
|
||||
gmio_adv_encode_uint16_le(info->general_purpose_flags, &buff);
|
||||
gmio_adv_encode_uint16_le(info->compress_method, &buff);
|
||||
/* 2-bytes last mod file time + 2-bytes last mod file date */
|
||||
const struct tm* lastmod = gmio_nonnull_datetime(info->lastmod_datetime);
|
||||
buff = gmio_adv_encode_uint32_le(gmio_to_msdos_datetime(lastmod), buff);
|
||||
buff = gmio_adv_encode_uint32_le(
|
||||
use_data_descriptor ? 0 : info->crc32, buff);
|
||||
buff = gmio_adv_encode_uint32_le(
|
||||
use_data_descriptor ? 0 : info->compressed_size, buff);
|
||||
buff = gmio_adv_encode_uint32_le(
|
||||
use_data_descriptor ? 0 : info->uncompressed_size, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->filename_len, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->extrafield_len, buff);
|
||||
gmio_adv_encode_uint32_le(gmio_to_msdos_datetime(lastmod), &buff);
|
||||
gmio_adv_encode_uint32_le(use_data_descriptor ? 0 : info->crc32, &buff);
|
||||
gmio_adv_encode_uint32_le(
|
||||
use_data_descriptor ? 0 : info->compressed_size, &buff);
|
||||
gmio_adv_encode_uint32_le(
|
||||
use_data_descriptor ? 0 : info->uncompressed_size, &buff);
|
||||
gmio_adv_encode_uint16_le(info->filename_len, &buff);
|
||||
gmio_adv_encode_uint16_le(info->extrafield_len, &buff);
|
||||
|
||||
/* Write to stream */
|
||||
const size_t expected_written_len =
|
||||
sizeof(fixed_data) + info->filename_len + info->extrafield_len;
|
||||
sizeof(bytes) + info->filename_len + info->extrafield_len;
|
||||
size_t written_len = 0;
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, fixed_data, sizeof(fixed_data));
|
||||
gmio_stream_write_bytes(stream, bytes, sizeof(bytes));
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, info->filename, info->filename_len);
|
||||
written_len +=
|
||||
@ -321,16 +309,16 @@ size_t gmio_zip_read_data_descriptor(
|
||||
struct gmio_zip_data_descriptor *info,
|
||||
int* ptr_error)
|
||||
{
|
||||
uint8_t buff[GMIO_ZIP_SIZE_DATA_DESCRIPTOR];
|
||||
const uint8_t* buffit = buff;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_DATA_DESCRIPTOR];
|
||||
const uint8_t* buff = bytes;
|
||||
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, bytes, sizeof(bytes));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(bytes)))
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_STREAM, ptr_error);
|
||||
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buff);
|
||||
info->compressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
info->uncompressed_size = gmio_adv_decode_uint32_le(&buff);
|
||||
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_OK, ptr_error);
|
||||
}
|
||||
@ -341,16 +329,16 @@ size_t gmio_zip64_read_data_descriptor(
|
||||
int* ptr_error)
|
||||
{
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
uint8_t buff[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR];
|
||||
const uint8_t* buffit = buff;
|
||||
uint8_t bytes[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR];
|
||||
const uint8_t* buff = bytes;
|
||||
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
|
||||
const size_t read_len = gmio_stream_read_bytes(stream, bytes, sizeof(bytes));
|
||||
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(bytes)))
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_STREAM, ptr_error);
|
||||
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buffit);
|
||||
info->compressed_size = gmio_adv_decode_uint64_le(&buffit);
|
||||
info->uncompressed_size = gmio_adv_decode_uint64_le(&buffit);
|
||||
info->crc32 = gmio_adv_decode_uint32_le(&buff);
|
||||
info->compressed_size = gmio_adv_decode_uint64_le(&buff);
|
||||
info->uncompressed_size = gmio_adv_decode_uint64_le(&buff);
|
||||
|
||||
return gmio_zip_io_returnerr(read_len, GMIO_ERROR_OK, ptr_error);
|
||||
#else
|
||||
@ -364,41 +352,41 @@ size_t gmio_zip_write_central_directory_header(
|
||||
const struct gmio_zip_central_directory_header *info,
|
||||
int* ptr_error)
|
||||
{
|
||||
uint8_t fixed_data[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER];
|
||||
uint8_t* buff = fixed_data;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER];
|
||||
uint8_t* buff = bytes;
|
||||
|
||||
buff = gmio_adv_encode_uint32_le(0x02014b50, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->version_made_by, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->version_needed_to_extract, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->general_purpose_flags, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->compress_method, buff);
|
||||
gmio_adv_encode_uint32_le(0x02014b50, &buff);
|
||||
gmio_adv_encode_uint16_le(info->version_made_by, &buff);
|
||||
gmio_adv_encode_uint16_le(info->version_needed_to_extract, &buff);
|
||||
gmio_adv_encode_uint16_le(info->general_purpose_flags, &buff);
|
||||
gmio_adv_encode_uint16_le(info->compress_method, &buff);
|
||||
/* 2-bytes last mod file time + 2-bytes last mod file date */
|
||||
const struct tm* lastmod = gmio_nonnull_datetime(info->lastmod_datetime);
|
||||
buff = gmio_adv_encode_uint32_le(gmio_to_msdos_datetime(lastmod), buff);
|
||||
buff = gmio_adv_encode_uint32_le(info->crc32, buff);
|
||||
gmio_adv_encode_uint32_le(gmio_to_msdos_datetime(lastmod), &buff);
|
||||
gmio_adv_encode_uint32_le(info->crc32, &buff);
|
||||
const uint32_t compressed_size =
|
||||
info->use_zip64 ? UINT32_MAX : info->compressed_size;
|
||||
const uint32_t uncompressed_size =
|
||||
info->use_zip64 ? UINT32_MAX : info->uncompressed_size;
|
||||
buff = gmio_adv_encode_uint32_le(compressed_size, buff);
|
||||
buff = gmio_adv_encode_uint32_le(uncompressed_size, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->filename_len, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->extrafield_len, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->filecomment_len, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->disk_nb_start, buff);
|
||||
buff = gmio_adv_encode_uint16_le(info->internal_file_attrs, buff);
|
||||
buff = gmio_adv_encode_uint32_le(info->external_file_attrs, buff);
|
||||
gmio_adv_encode_uint32_le(compressed_size, &buff);
|
||||
gmio_adv_encode_uint32_le(uncompressed_size, &buff);
|
||||
gmio_adv_encode_uint16_le(info->filename_len, &buff);
|
||||
gmio_adv_encode_uint16_le(info->extrafield_len, &buff);
|
||||
gmio_adv_encode_uint16_le(info->filecomment_len, &buff);
|
||||
gmio_adv_encode_uint16_le(info->disk_nb_start, &buff);
|
||||
gmio_adv_encode_uint16_le(info->internal_file_attrs, &buff);
|
||||
gmio_adv_encode_uint32_le(info->external_file_attrs, &buff);
|
||||
const uint32_t relative_offset_local_header =
|
||||
info->use_zip64 ? UINT32_MAX : info->relative_offset_local_header;
|
||||
buff = gmio_adv_encode_uint32_le(relative_offset_local_header, buff);
|
||||
gmio_adv_encode_uint32_le(relative_offset_local_header, &buff);
|
||||
|
||||
/* Write to stream */
|
||||
const size_t expected_written_len =
|
||||
sizeof(fixed_data)
|
||||
sizeof(bytes)
|
||||
+ info->filename_len + info->extrafield_len + info->filecomment_len;
|
||||
size_t written_len = 0;
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, fixed_data, sizeof(fixed_data));
|
||||
gmio_stream_write_bytes(stream, bytes, sizeof(bytes));
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, info->filename, info->filename_len);
|
||||
written_len +=
|
||||
@ -421,14 +409,13 @@ size_t gmio_zip64_write_extrafield_extended_info(
|
||||
}
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
/* Tag */
|
||||
buff = gmio_adv_encode_uint16_le(0x0001, buff);
|
||||
gmio_adv_encode_uint16_le(0x0001, &buff);
|
||||
/* Size of the "extra" block */
|
||||
buff = gmio_adv_encode_uint16_le(
|
||||
GMIO_ZIP64_SIZE_EXTRAFIELD_EXTENDED_INFO - 2, buff);
|
||||
buff = gmio_adv_encode_uint64_le(info->uncompressed_size, buff);
|
||||
buff = gmio_adv_encode_uint64_le(info->compressed_size, buff);
|
||||
buff = gmio_adv_encode_uint64_le(info->relative_offset_local_header, buff);
|
||||
buff = gmio_adv_encode_uint32_le(info->disk_nb_start, buff);
|
||||
gmio_adv_encode_uint16_le(GMIO_ZIP64_SIZE_EXTRAFIELD_EXTENDED_INFO - 2, &buff);
|
||||
gmio_adv_encode_uint64_le(info->uncompressed_size, &buff);
|
||||
gmio_adv_encode_uint64_le(info->compressed_size, &buff);
|
||||
gmio_adv_encode_uint64_le(info->relative_offset_local_header, &buff);
|
||||
gmio_adv_encode_uint32_le(info->disk_nb_start, &buff);
|
||||
return gmio_zip_io_returnerr(
|
||||
GMIO_ZIP64_SIZE_EXTRAFIELD_EXTENDED_INFO,
|
||||
GMIO_ERROR_OK,
|
||||
@ -444,42 +431,41 @@ size_t gmio_zip_write_end_of_central_directory_record(
|
||||
const struct gmio_zip_end_of_central_directory_record *info,
|
||||
int* ptr_error)
|
||||
{
|
||||
uint8_t fixed_data[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD];
|
||||
uint8_t* buff = fixed_data;
|
||||
uint8_t bytes[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD];
|
||||
uint8_t* buff = bytes;
|
||||
|
||||
/* 4-bytes magic number 0x06054b50 */
|
||||
buff = gmio_adv_encode_uint32_le(0x06054b50, buff);
|
||||
gmio_adv_encode_uint32_le(0x06054b50, &buff);
|
||||
|
||||
/* 2-bytes number of this disk */
|
||||
const uint16_t disk_nb = info->use_zip64 ? UINT16_MAX : info->disk_nb;
|
||||
buff = gmio_adv_encode_uint16_le(disk_nb, buff);
|
||||
gmio_adv_encode_uint16_le(disk_nb, &buff);
|
||||
|
||||
/* 2-bytes number of the disk with the start of the central directory */
|
||||
const uint16_t disk_nb_with_start_of_central_dir =
|
||||
info->use_zip64 ?
|
||||
UINT16_MAX :
|
||||
info->disk_nb_with_start_of_central_dir;
|
||||
buff = gmio_adv_encode_uint16_le(disk_nb_with_start_of_central_dir, buff);
|
||||
gmio_adv_encode_uint16_le(disk_nb_with_start_of_central_dir, &buff);
|
||||
|
||||
/* 2-bytes total number of entries in the central directory on this disk */
|
||||
const uint16_t total_entry_count_in_central_dir_on_disk =
|
||||
info->use_zip64 ?
|
||||
UINT16_MAX :
|
||||
info->total_entry_count_in_central_dir_on_disk;
|
||||
buff = gmio_adv_encode_uint16_le(
|
||||
total_entry_count_in_central_dir_on_disk, buff);
|
||||
gmio_adv_encode_uint16_le(total_entry_count_in_central_dir_on_disk, &buff);
|
||||
|
||||
/* 2-bytes total number of entries in the central directory */
|
||||
const uint16_t total_entry_count_in_central_dir =
|
||||
info->use_zip64 ?
|
||||
UINT16_MAX :
|
||||
info->total_entry_count_in_central_dir;
|
||||
buff = gmio_adv_encode_uint16_le(total_entry_count_in_central_dir, buff);
|
||||
gmio_adv_encode_uint16_le(total_entry_count_in_central_dir, &buff);
|
||||
|
||||
/* 4-bytes size of the central directory */
|
||||
const uint32_t central_dir_size =
|
||||
info->use_zip64 ? UINT32_MAX : info->central_dir_size;
|
||||
buff = gmio_adv_encode_uint32_le(central_dir_size, buff);
|
||||
gmio_adv_encode_uint32_le(central_dir_size, &buff);
|
||||
|
||||
/* 4-bytes offset of start of central directory with respect to the starting
|
||||
* disk number */
|
||||
@ -487,18 +473,17 @@ size_t gmio_zip_write_end_of_central_directory_record(
|
||||
info->use_zip64 ?
|
||||
UINT32_MAX :
|
||||
info->start_offset_central_dir_from_disk_start_nb;
|
||||
buff = gmio_adv_encode_uint32_le(
|
||||
start_offset_central_dir_from_disk_start_nb, buff);
|
||||
gmio_adv_encode_uint32_le(start_offset_central_dir_from_disk_start_nb, &buff);
|
||||
|
||||
/* 2-bytes .ZIP file comment length */
|
||||
buff = gmio_adv_encode_uint16_le(info->filecomment_len, buff);
|
||||
gmio_adv_encode_uint16_le(info->filecomment_len, &buff);
|
||||
|
||||
/* Write to stream */
|
||||
const size_t expected_written_len =
|
||||
sizeof(fixed_data) + info->filecomment_len;
|
||||
sizeof(bytes) + info->filecomment_len;
|
||||
size_t written_len = 0;
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, fixed_data, sizeof(fixed_data));
|
||||
gmio_stream_write_bytes(stream, bytes, sizeof(bytes));
|
||||
written_len +=
|
||||
gmio_stream_write_bytes(stream, info->filecomment, info->filecomment_len);
|
||||
return gmio_zip_write_returnhelper(
|
||||
|
Loading…
Reference in New Issue
Block a user