Some code refactoring.

This commit is contained in:
LoRd_MuldeR 2022-03-01 23:34:50 +01:00
parent b95e578e33
commit ca16052112
Signed by: mulder
GPG Key ID: 2B5913365F57E03F

View File

@ -40,11 +40,24 @@ static const char PASSWD_SYMBOLS[] =
#define PASSPHRASE_BUFFSIZE (SLUNKCRYPT_PWDLEN_MAX + 2U)
static void trim_end_of_line(char *const buffer)
{
size_t length;
for (length = strlen(buffer); length > 0U; --length)
{
const char last = buffer[length - 1U];
if ((last != '\r') && (last != '\n') && (last != '\f'))
{
break;
}
}
buffer[length] = '\0';
}
char *read_passphrase(const CHR *const file_name)
{
size_t str_len = 0U;
CHR *passphrase_path = NULL;
char *buffer = NULL;
CHR *passphrase_path = NULL;
FILE *passphrase_file = NULL;
if ((!file_name) || (!file_name[0U]))
@ -84,11 +97,7 @@ char *read_passphrase(const CHR *const file_name)
buffer[0U] = '\0';
goto finish;
}
str_len = strlen(buffer);
while ((str_len > 0U) && ((buffer[str_len - 1U] == '\r') || (buffer[str_len - 1U] == '\n')))
{
buffer[--str_len] = '\0';
}
trim_end_of_line(buffer);
}
while (!buffer[0U]);