Skip to content

Commit

Permalink
Fixed compilation on on-Windows platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaGrebnov committed Jan 6, 2022
1 parent 0b4dc3c commit 81718b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions bsc-m03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static int compress_file(const char * input_file_name, const char * output_file_
{
if (FILE * output_file = fopen(output_file_name, "wb"))
{
fseek(input_file, 0, SEEK_END); int64_t remaining_size = _ftelli64(input_file); rewind(input_file);
fseeko(input_file, 0, SEEK_END); int64_t remaining_size = ftello(input_file); rewind(input_file);

if (uint8_t * buffer = (uint8_t *)malloc(std::min(remaining_size, (int64_t)max_block_size) * sizeof(uint8_t)))
{
Expand Down Expand Up @@ -278,7 +278,7 @@ static int compress_file(const char * input_file_name, const char * output_file_

if (remaining_size == 0)
{
fprintf(stdout, "\r%.55s compressed from %lld into %lld in %.3f seconds (%.3f bps).\n", input_file_name, input_bytes, output_bytes, ((double)clock() - start_time) / CLOCKS_PER_SEC, (8.0 * symbol_size * output_bytes) / input_bytes);
fprintf(stdout, "\r%.55s compressed from %lld into %lld in %.3f seconds (%.3f bps).\n", input_file_name, (long long int)input_bytes, (long long int)output_bytes, ((double)clock() - start_time) / CLOCKS_PER_SEC, (8.0 * symbol_size * output_bytes) / input_bytes);
}

free(buffer);
Expand Down Expand Up @@ -315,7 +315,7 @@ static int decompress_file(const char * input_file_name, const char * output_fil
int32_t max_block_size;
if (fread(&max_block_size, sizeof(uint8_t), sizeof(max_block_size), input_file) == sizeof(max_block_size))
{
fseek(input_file, 0, SEEK_END); int64_t remaining_size = _ftelli64(input_file); rewind(input_file);
fseeko(input_file, 0, SEEK_END); int64_t remaining_size = ftello(input_file); rewind(input_file);

if (uint8_t * buffer = (uint8_t *)malloc(max_block_size * sizeof(uint8_t)))
{
Expand Down Expand Up @@ -366,7 +366,7 @@ static int decompress_file(const char * input_file_name, const char * output_fil

if (remaining_size == 0)
{
fprintf(stdout, "\r%.55s decompressed from %lld into %lld in %.3f seconds.\n", input_file_name, input_bytes, output_bytes, ((double)clock() - start_time) / CLOCKS_PER_SEC);
fprintf(stdout, "\r%.55s decompressed from %lld into %lld in %.3f seconds.\n", input_file_name, (long long int)input_bytes, (long long int)output_bytes, ((double)clock() - start_time) / CLOCKS_PER_SEC);
}

free(buffer);
Expand Down
5 changes: 5 additions & 0 deletions common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ NOTICE: This file has been modified for use in the bsc-m03 project.
#ifndef _LIBBSC_PLATFORM_H
#define _LIBBSC_PLATFORM_H

#ifdef _MSC_VER
#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
#define ftello(stream) _ftelli64(stream)
#endif

#if defined(_MSC_VER)
#include <intrin.h>
#else
Expand Down
4 changes: 2 additions & 2 deletions m03_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class m03_model
{
int64_t min_value = (1ll << (bit + 0)) - 1;
int64_t max_value = (1ll << (bit + 1)) - 2;
int64_t min = std::max(remaining_count - (remaining_max / (max_value + 1)), 0ll);
int64_t min = std::max(remaining_count - (remaining_max / (max_value + 1)), (int64_t)0);
int64_t max = remaining_count * max_value < remaining_min ? remaining_count - 1 : remaining_count;

this->coder->EncodeValue((unsigned int)min, (unsigned int)bit_freq[bit], (unsigned int)max);
Expand Down Expand Up @@ -153,7 +153,7 @@ class m03_model
{
int64_t min_value = (1ll << (bit + 0)) - 1;
int64_t max_value = (1ll << (bit + 1)) - 2;
int64_t min = std::max(remaining_count - (remaining_max / (max_value + 1)), 0ll);
int64_t min = std::max(remaining_count - (remaining_max / (max_value + 1)), (int64_t)0);
int64_t max = remaining_count * max_value < remaining_min ? remaining_count - 1 : remaining_count;

bit_freq[bit] = this->coder->DecodeValue((unsigned int)min, (unsigned int)max);
Expand Down

0 comments on commit 81718b4

Please sign in to comment.