Refactored progress indicator update + increase file I/O buffer size.
This commit is contained in:
parent
342562cf2e
commit
fdc1c8b0d8
@ -49,6 +49,9 @@ static int open_files(FILE **const file_in, FILE **const file_out, const CHR *co
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setvbuf(*file_in, NULL, _IOFBF, (((8U * BUFFER_SIZE) + (BUFSIZ - 1U)) / BUFSIZ) * BUFSIZ);
|
||||||
|
setvbuf(*file_out, NULL, _IOFBF, (((8U * BUFFER_SIZE) + (BUFSIZ - 1U)) / BUFSIZ) * BUFSIZ);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +62,18 @@ static void init_slunk_param(slunkparam_t *const param, const crypt_options_t *c
|
|||||||
param->thread_count = options->thread_count;
|
param->thread_count = options->thread_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UPDATE_PROGRESS_INDICATOR(CLK_UPDATE, CURRENT, TOTAL) do \
|
||||||
|
{ \
|
||||||
|
const uint64_t clk_now = clock_read(); \
|
||||||
|
if ((clk_now < (CLK_UPDATE)) || (clk_now - (CLK_UPDATE) > update_interval)) \
|
||||||
|
{ \
|
||||||
|
FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%% "), ((CURRENT) / ((double)(TOTAL))) * 100.0); \
|
||||||
|
fflush(stderr); \
|
||||||
|
CLK_UPDATE = clk_now; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while(0)
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Encrypt
|
// Encrypt
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
@ -118,8 +133,8 @@ int encrypt(const char *const passphrase, const CHR *const input_path, const CHR
|
|||||||
goto clean_up;
|
goto clean_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t bytes_read = 0U, clk_now, clk_update = clk_now = clock_read();
|
uint64_t bytes_read = 0U, clk_update = clock_read();
|
||||||
const uint64_t update_interval = (uint64_t)(clock_freq() * 1.0625);
|
const uint64_t update_interval = (uint64_t)(clock_freq() * 1.414);
|
||||||
|
|
||||||
blake2s_t blake2s_state;
|
blake2s_t blake2s_state;
|
||||||
blake2s_init(&blake2s_state);
|
blake2s_init(&blake2s_state);
|
||||||
@ -151,12 +166,7 @@ int encrypt(const char *const passphrase, const CHR *const input_path, const CHR
|
|||||||
{
|
{
|
||||||
break; /*EOF*/
|
break; /*EOF*/
|
||||||
}
|
}
|
||||||
if (((clk_now = clock_read()) < clk_update) || (clk_now - clk_update > update_interval))
|
UPDATE_PROGRESS_INDICATOR(clk_update, bytes_read, file_size);
|
||||||
{
|
|
||||||
FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%% "), (bytes_read / ((double)file_size)) * 100.0);
|
|
||||||
fflush(stderr);
|
|
||||||
clk_update = clk_now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ferror(file_in))
|
if (ferror(file_in))
|
||||||
@ -308,8 +318,8 @@ int decrypt(const char *const passphrase, const CHR *const input_path, const CHR
|
|||||||
goto clean_up;
|
goto clean_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t bytes_read = sizeof(uint64_t), clk_now, clk_update = clk_now = clock_read();
|
uint64_t bytes_read = sizeof(uint64_t), clk_update = clock_read();
|
||||||
const uint64_t update_interval = (uint64_t)(clock_freq() * 1.0625);
|
const uint64_t update_interval = (uint64_t)(clock_freq() * 1.414);
|
||||||
const uint64_t read_limit = round_down(file_size, sizeof(uint64_t)) - (2U * sizeof(uint64_t));
|
const uint64_t read_limit = round_down(file_size, sizeof(uint64_t)) - (2U * sizeof(uint64_t));
|
||||||
|
|
||||||
blake2s_t blake2s_state;
|
blake2s_t blake2s_state;
|
||||||
@ -342,12 +352,7 @@ int decrypt(const char *const passphrase, const CHR *const input_path, const CHR
|
|||||||
{
|
{
|
||||||
break; /*EOF*/
|
break; /*EOF*/
|
||||||
}
|
}
|
||||||
if (((clk_now = clock_read()) < clk_update) || (clk_now - clk_update > update_interval))
|
UPDATE_PROGRESS_INDICATOR(clk_update, bytes_read, read_limit);
|
||||||
{
|
|
||||||
FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%% "), (bytes_read / ((double)read_limit)) * 100.0);
|
|
||||||
fflush(stderr);
|
|
||||||
clk_update = clk_now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ferror(file_in))
|
if (ferror(file_in))
|
||||||
|
Loading…
Reference in New Issue
Block a user