promote chop_* functions into fko_util
This commit is contained in:
@@ -2348,6 +2348,7 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
|
||||
case GPG_HOME_DIR:
|
||||
options->use_gpg = 1;
|
||||
strlcpy(options->gpg_home_dir, optarg, sizeof(options->gpg_home_dir));
|
||||
chop_char(options->gpg_home_dir, PATH_SEP);
|
||||
add_var_to_bitmask(FWKNOP_CLI_ARG_USE_GPG, &var_bitmask);
|
||||
add_var_to_bitmask(FWKNOP_CLI_ARG_GPG_HOMEDIR, &var_bitmask);
|
||||
break;
|
||||
|
||||
@@ -622,6 +622,39 @@ is_base64(const unsigned char * const buf, const unsigned short int len)
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
chop_char(char *str, const char chop)
|
||||
{
|
||||
if(str != NULL
|
||||
&& str[0] != 0x0
|
||||
&& strlen(str) > 1 /* don't truncate a single-char string */
|
||||
&& str[strlen(str)-1] == chop)
|
||||
str[strlen(str)-1] = 0x0;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
chop_newline(char *str)
|
||||
{
|
||||
chop_char(str, 0x0a);
|
||||
return;
|
||||
}
|
||||
|
||||
void chop_spaces(char *str)
|
||||
{
|
||||
int i;
|
||||
if (str != NULL && str[0] != 0x0)
|
||||
{
|
||||
for (i=strlen(str)-1; i > 0; i--)
|
||||
{
|
||||
if(str[i] != 0x20)
|
||||
break;
|
||||
str[i] = 0x0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump a FKO context to a buffer
|
||||
*
|
||||
|
||||
@@ -54,6 +54,10 @@ int zero_buf(char *buf, int len);
|
||||
const char * enc_type_inttostr(const int type);
|
||||
const char * msg_type_inttostr(const int type);
|
||||
|
||||
void chop_newline(char *str);
|
||||
void chop_char(char *str, const char chop);
|
||||
void chop_spaces(char *str);
|
||||
|
||||
#if !HAVE_STRLCAT
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
@@ -1210,8 +1210,7 @@ config_init(fko_srv_options_t *opts, int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case ACCESS_FOLDER:
|
||||
if(strlen(optarg) > 1)
|
||||
chop_char(optarg, PATH_SEP);
|
||||
chop_char(optarg, PATH_SEP);
|
||||
if (is_valid_dir(optarg))
|
||||
set_config_entry(opts, CONF_ACCESS_FOLDER, optarg);
|
||||
else
|
||||
@@ -1286,8 +1285,7 @@ config_init(fko_srv_options_t *opts, int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case GPG_HOME_DIR:
|
||||
if(strlen(optarg) > 1)
|
||||
chop_char(optarg, PATH_SEP);
|
||||
chop_char(optarg, PATH_SEP);
|
||||
if (is_valid_dir(optarg))
|
||||
set_config_entry(opts, CONF_GPG_HOME_DIR, optarg);
|
||||
else
|
||||
|
||||
@@ -213,36 +213,6 @@ verify_file_perms_ownership(const char *file)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
chop_char(char *str, const char chop)
|
||||
{
|
||||
if(str != NULL && str[0] != 0x0 && str[strlen(str)-1] == chop)
|
||||
str[strlen(str)-1] = 0x0;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
chop_newline(char *str)
|
||||
{
|
||||
chop_char(str, 0x0a);
|
||||
return;
|
||||
}
|
||||
|
||||
void chop_spaces(char *str)
|
||||
{
|
||||
int i;
|
||||
if (str != NULL && str[0] != 0x0)
|
||||
{
|
||||
for (i=strlen(str)-1; i > 0; i--)
|
||||
{
|
||||
if(str[i] != 0x20)
|
||||
break;
|
||||
str[i] = 0x0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
truncate_partial_line(char *str)
|
||||
{
|
||||
|
||||
@@ -66,9 +66,6 @@ int is_valid_dir(const char *path);
|
||||
int is_valid_exe(const char *path);
|
||||
int is_valid_file(const char *path);
|
||||
int verify_file_perms_ownership(const char *file);
|
||||
void chop_newline(char *str);
|
||||
void chop_char(char *str, const char chop);
|
||||
void chop_spaces(char *str);
|
||||
void truncate_partial_line(char *str);
|
||||
int is_digits(const char * const str);
|
||||
int strtoargv(const char * const args_str, char **argv_new, int *argc_new,
|
||||
|
||||
Reference in New Issue
Block a user