strings: renaming functions to have a str_ prefix

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
Otavio Pontes
2020-04-23 08:55:45 -07:00
parent 1d8caf04f4
commit bbd7da491d
36 changed files with 141 additions and 141 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ static bool parse_opt(int opt, UNUSED_PARAM char *optarg)
cmdline_option_version = -1;
return true;
}
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
+2 -2
View File
@@ -77,7 +77,7 @@ static bool parse_opt(int opt, char *optarg)
switch (opt) {
case 'V':
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
@@ -108,7 +108,7 @@ static bool parse_opt(int opt, char *optarg)
* a possible existing list parsed from a config file, we want to replace it, so
* we need to delete the existing list first */
list_free_list(cmdline_option_bundles);
cmdline_option_bundles = string_split(",", optarg);
cmdline_option_bundles = str_split(",", optarg);
if (!cmdline_option_bundles) {
error("Missing required --bundles argument\n\n");
return false;
+2 -2
View File
@@ -93,7 +93,7 @@ static bool parse_opt(int opt, char *optarg)
cmdline_option_repo = strdup_or_die(optarg);
return true;
case 'V':
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
@@ -116,7 +116,7 @@ static bool parse_opt(int opt, char *optarg)
* we need to delete the existing list first */
list_free_list(cmdline_option_bundles);
cmdline_option_bundles = NULL;
cmdline_option_bundles = string_split(",", optarg);
cmdline_option_bundles = str_split(",", optarg);
if (!cmdline_option_bundles) {
error("Missing required --bundles argument\n\n");
return false;
+2 -2
View File
@@ -69,7 +69,7 @@ static bool parse_opt(int opt, char *optarg)
return true;
}
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
@@ -315,7 +315,7 @@ enum swupd_code third_party_update_main(int argc, char **argv)
/* update the template */
ret = sys_write_file(template_file, SCRIPT_TEMPLATE, string_len(SCRIPT_TEMPLATE));
ret = sys_write_file(template_file, SCRIPT_TEMPLATE, str_len(SCRIPT_TEMPLATE));
if (ret < 0) {
error("The wrapper scripts template file %s failed to be updated\n", template_file);
ret_code = SWUPD_COULDNT_WRITE_FILE;
+2 -2
View File
@@ -270,7 +270,7 @@ static struct list *generate_bundles_to_install(struct list *bundles)
char *bundle = iter->data;
struct list *alias_bundles = get_alias_bundles(aliases, bundle);
char *alias_list_str = string_join(", ", alias_bundles);
char *alias_list_str = str_join(", ", alias_bundles);
if (strcmp(bundle, alias_list_str) != 0) {
info("Alias %s will install bundle(s): %s\n", bundle, alias_list_str);
@@ -472,7 +472,7 @@ clean_and_exit:
}
/* report command result to telemetry */
bundles_list_str = string_join(", ", bundles);
bundles_list_str = str_join(", ", bundles);
if (ret == 0) {
level = TELEMETRY_LOW;
} else if (ret == SWUPD_INVALID_BUNDLE) {
+1 -1
View File
@@ -78,7 +78,7 @@ static bool parse_opt(int opt, UNUSED_PARAM char *optarg)
cmdline_option_version = -1;
return true;
}
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
+1 -1
View File
@@ -442,7 +442,7 @@ out_subs:
manifest_free(current_mom);
free_subscriptions(&subs);
out:
bundles_list_str = string_join(", ", bundles);
bundles_list_str = str_join(", ", bundles);
telemetry(TELEMETRY_CRIT,
"bundleremove",
"bundle=%s\n"
+1 -1
View File
@@ -106,7 +106,7 @@ enum swupd_code check_update(void)
if (latest_version_in_format > 0) {
info_verbose("Latest version in format %s: %d", globals.format_string, latest_version_in_format);
if (strtoi_err(globals.format_string, &tmp_format) != 0 ||
if (str_to_int(globals.format_string, &tmp_format) != 0 ||
tmp_format != format_in_format) {
print_format(format_in_format);
} else {
+2 -2
View File
@@ -185,7 +185,7 @@ static enum swupd_code remove_if(const char *path, bool dry_run, remove_predicat
static bool is_fullfile(const char UNUSED_PARAM *dir, const struct dirent *entry)
{
return string_len(entry->d_name) == (SWUPD_HASH_LEN - 1);
return str_len(entry->d_name) == (SWUPD_HASH_LEN - 1);
}
static bool is_pack_indicator(const char UNUSED_PARAM *dir, const struct dirent *entry)
@@ -196,7 +196,7 @@ static bool is_pack_indicator(const char UNUSED_PARAM *dir, const struct dirent
static const size_t suffix_len = sizeof(suffix) - 1;
const char *name = entry->d_name;
size_t len = string_len(name);
size_t len = str_len(name);
if (len < (prefix_len + suffix_len)) {
return false;
}
+1 -1
View File
@@ -91,7 +91,7 @@ static bool check_delta_filename(const char *delta_name, char *from, char *to)
/* Note: SWUPD_HASH_LEN accounts for the NUL-terminator after the hash. */
const size_t hash_len = SWUPD_HASH_LEN - 1;
if (string_len(s) != (hash_len * 2 + 1)) {
if (str_len(s) != (hash_len * 2 + 1)) {
return false;
}
+3 -3
View File
@@ -110,7 +110,7 @@ enum swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix
int rc;
int ret;
path_prefix_len = string_len(globals.path_prefix);
path_prefix_len = str_len(globals.path_prefix);
path_whitelist = whitelist;
rc = nftw(start, &record_filename, 0, FTW_ACTIONRETVAL | FTW_PHYS | FTW_MOUNT);
const char *skip_dir = NULL; /* Skip files below this in printout */
@@ -145,7 +145,7 @@ enum swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix
}
int skip_len = 0; /* Length of directory name we are skipping
* could have used string_len(skip_dir), but speed! */
* could have used str_len(skip_dir), but speed! */
/* list files/directories which are extra.
* This is reverse so that files are removed before their parent dirs */
for (int i = nF - 1; i >= 0; i--) {
@@ -165,7 +165,7 @@ enum swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix
}
if (F[i].dir) { /* Start of new dir to skip */
skip_dir = F[i].filename;
skip_len = string_len(skip_dir);
skip_len = str_len(skip_dir);
ret = handle(F[i].filename, true, fix);
} else {
ret = handle(F[i].filename, false, fix);
+1 -1
View File
@@ -72,7 +72,7 @@ static void foreach_open_fd(void(pf)(int, void *), void *arg)
continue;
}
err = strtoi_err_endptr(entry->d_name, &ep, &n);
err = str_to_int_endptr(entry->d_name, &ep, &n);
if (err != 0) {
warn("invalid fd\n");
}
+6 -6
View File
@@ -347,7 +347,7 @@ bool set_path_prefix(char *path)
goto error;
}
len = string_len(new_path);
len = str_len(new_path);
if (!len || (new_path[len - 1] != '/')) {
char *tmp;
@@ -420,7 +420,7 @@ static bool set_assume_option(char *option)
return false;
}
option_lower = str_tolower(option);
option_lower = str_to_lower(option);
if (strcmp(option_lower, "y") == 0 || strcmp(option_lower, "yes") == 0) {
globals.user_interaction = NON_INTERACTIVE_ASSUME_YES;
@@ -575,7 +575,7 @@ static bool global_parse_opt(int opt, char *optarg)
set_content_url(optarg);
return true;
case 'P':
err = strtoi_err(optarg, &globals.update_server_port);
err = str_to_int(optarg, &globals.update_server_port);
if (err < 0 || globals.update_server_port < 0) {
error("Invalid --port argument: %s\n\n", optarg);
return false;
@@ -619,21 +619,21 @@ static bool global_parse_opt(int opt, char *optarg)
globals.user_defined_cert_path = true;
return true;
case 'W':
err = strtoi_err(optarg, &max_parallel_downloads);
err = str_to_int(optarg, &max_parallel_downloads);
if (err < 0 || max_parallel_downloads <= 0) {
error("Invalid --max-parallel-downloads argument: %s\n\n", optarg);
return false;
}
return true;
case 'r':
err = strtoi_err(optarg, &globals.max_retries);
err = str_to_int(optarg, &globals.max_retries);
if (err < 0 || globals.max_retries < 0) {
error("Invalid --max-retries argument: %s\n\n", optarg);
return false;
}
return true;
case 'd':
err = strtoi_err(optarg, &globals.retry_delay);
err = str_to_int(optarg, &globals.retry_delay);
if (err < 0 || globals.retry_delay < 0 || globals.retry_delay > 60) {
error("Invalid --retry-delay argument: %s (should be between 0 - %d seconds)\n\n", optarg, MAX_DELAY);
return false;
+1 -1
View File
@@ -16,7 +16,7 @@
extern "C" {
#endif
#define optarg_to_bool(_optarg) (_optarg ? strtobool(_optarg) : true)
#define optarg_to_bool(_optarg) (_optarg ? str_to_bool(_optarg) : true)
enum user_interaction {
INTERACTIVE = 0,
+1 -1
View File
@@ -106,7 +106,7 @@ static void hmac_sha256_for_string(char *hash,
return;
}
hmac_sha256_for_data(hash, key, key_len, (const unsigned char *)str, string_len(str));
hmac_sha256_for_data(hash, key, key_len, (const unsigned char *)str, str_len(str));
}
static void hmac_compute_key(const char *filename,
+8 -8
View File
@@ -341,7 +341,7 @@ static int get_version_from_path(const char *abs_path)
ret = get_value_from_path(&ret_str, abs_path, true);
if (ret == 0) {
int err = strtoi_err(ret_str, &val);
int err = str_to_int(ret_str, &val);
free_and_clear_pointer(&ret_str);
if (err != 0) {
@@ -404,7 +404,7 @@ bool is_under_mounted_directory(const char *filename)
string_or_die(&fname, ":%s:", tmp);
free_and_clear_pointer(&tmp);
err = strncmp(fname, mountpoint, string_len(mountpoint));
err = strncmp(fname, mountpoint, str_len(mountpoint));
free_and_clear_pointer(&fname);
if (err == 0) {
free_and_clear_pointer(&mountpoint);
@@ -453,7 +453,7 @@ void swupd_deinit(void)
void remove_trailing_slash(char *url)
{
int len = string_len(url);
int len = str_len(url);
while (len > 0 && url[len - 1] == '/') {
len--;
@@ -632,7 +632,7 @@ bool string_in_list(char *string_to_check, struct list *list_to_check)
iter = list_head(list_to_check);
while (iter) {
if (strncmp(iter->data, string_to_check, string_len(string_to_check)) == 0) {
if (strncmp(iter->data, string_to_check, str_len(string_to_check)) == 0) {
return true;
}
@@ -654,7 +654,7 @@ bool is_compatible_format(int format_num)
char *format_manifest = NULL;
string_or_die(&format_manifest, "%d", format_num);
size_t len = string_len(globals.format_string);
size_t len = str_len(globals.format_string);
bool ret;
if (strncmp(globals.format_string, format_manifest, len) == 0) {
@@ -691,7 +691,7 @@ bool on_new_format(void)
return false;
}
err = strtoi_err(ret_str, &res);
err = str_to_int(ret_str, &res);
free_and_clear_pointer(&ret_str);
if (err != 0) {
@@ -928,7 +928,7 @@ void print_header(const char *header)
{
int header_length;
header_length = string_len(header);
header_length = str_len(header);
print_pattern("_", header_length + 1);
info("%s\n", header);
print_pattern("_", header_length + 1);
@@ -987,7 +987,7 @@ bool is_binary(const char *filename)
int i = 0;
while (binary_paths[i]) {
if (strncmp(filename, binary_paths[i], string_len(binary_paths[i])) == 0) {
if (strncmp(filename, binary_paths[i], str_len(binary_paths[i])) == 0) {
return true;
}
i++;
+2 -2
View File
@@ -57,14 +57,14 @@ static bool is_state(char *filename)
return true;
}
if ((string_len(filename) == 14) && (strncmp(filename, "/usr/src/debug", 14) == 0)) {
if ((str_len(filename) == 14) && (strncmp(filename, "/usr/src/debug", 14) == 0)) {
return false;
}
/* Compare the first part of the path, first all the entries inside
* kernel directory, then only the kernel directory */
if ((strncmp(filename, "/usr/src/kernel/", 16) == 0) ||
((string_len(filename) == 15) && (strncmp(filename, "/usr/src/kernel", 15) == 0))) {
((str_len(filename) == 15) && (strncmp(filename, "/usr/src/kernel", 15) == 0))) {
return false;
}
+1 -1
View File
@@ -245,7 +245,7 @@ int archives_check_single_file_tarball(const char *tarfilename, const char *file
// Remove trailing '/'
file_entry = archive_entry_pathname(entry);
file_len = string_len(file_entry);
file_len = str_len(file_entry);
if (file_entry[file_len - 1] == '/') {
file_len--;
}
+2 -2
View File
@@ -72,7 +72,7 @@ bool config_file_parse(const char *filename, parse_config_fn_t parse_config_fn,
free(section);
/* keys and sections in INI files are case insensitive,
* so we should convert them to a lower case first */
section = str_tolower(line + 1);
section = str_to_lower(line + 1);
continue;
}
@@ -101,7 +101,7 @@ bool config_file_parse(const char *filename, parse_config_fn_t parse_config_fn,
}
/* load the configuration value read in the application */
lkey = str_tolower(key);
lkey = str_to_lower(key);
if (parse_config_fn && !parse_config_fn(section, lkey, value, data)) {
warn("Unrecognized option '%s=%s' from section [%s] in the configuration file\n", key, value, section);
}
+1 -1
View File
@@ -56,7 +56,7 @@ static void json_message(const char *msg_type, const char *msg, va_list args_lis
/* make sure the type is all lower case */
if (msg_type) {
type = str_tolower(msg_type);
type = str_to_lower(msg_type);
}
/* build the full message based on all the arguments */
+1 -1
View File
@@ -96,7 +96,7 @@ static void log_internal(FILE *out, const char *file, int line, const char *labe
msg = vstr_or_die(format, args_list);
fprintf(out, "%s", msg);
if (msg[string_len(msg) - 1] != '\n') {
if (msg[str_len(msg) - 1] != '\n') {
fprintf(out, "\n");
}
free(msg);
+12 -12
View File
@@ -75,7 +75,7 @@ char *str_or_die(const char *fmt, ...)
return str;
}
char *string_join(const char *separator, struct list *strings)
char *str_join(const char *separator, struct list *strings)
{
char *str, *ret;
size_t str_size = 1; // 1 for '\0'
@@ -85,10 +85,10 @@ char *string_join(const char *separator, struct list *strings)
if (!separator) {
separator = "";
}
sep_size = string_len(separator);
sep_size = str_len(separator);
for (i = strings; i; i = i->next) {
str_size += string_len(i->data);
str_size += str_len(i->data);
str_size += sep_size;
}
@@ -112,7 +112,7 @@ error:
return NULL;
}
struct list *string_split(const char *separator, const char *string_to_split)
struct list *str_split(const char *separator, const char *string_to_split)
{
char *ctx = NULL;
struct list *split = NULL;
@@ -126,7 +126,7 @@ struct list *string_split(const char *separator, const char *string_to_split)
return split;
}
int strtoi_err_endptr(const char *str, char **endptr, int *value)
int str_to_int_endptr(const char *str, char **endptr, int *value)
{
long num;
int err;
@@ -150,10 +150,10 @@ int strtoi_err_endptr(const char *str, char **endptr, int *value)
return err;
}
int strtoi_err(const char *str, int *value)
int str_to_int(const char *str, int *value)
{
char *endptr;
int err = strtoi_err_endptr(str, &endptr, value);
int err = str_to_int_endptr(str, &endptr, value);
if (err) {
return err;
@@ -166,26 +166,26 @@ int strtoi_err(const char *str, int *value)
return 0;
}
char *str_tolower(const char *str)
char *str_to_lower(const char *str)
{
char *str_lower = malloc(string_len(str) + 1);
char *str_lower = malloc(str_len(str) + 1);
ON_NULL_ABORT(str_lower);
for (int i = 0; str[i]; i++) {
str_lower[i] = tolower(str[i]);
}
str_lower[string_len(str)] = '\0';
str_lower[str_len(str)] = '\0';
return str_lower;
}
bool strtobool(const char *str)
bool str_to_bool(const char *str)
{
char *str_lower;
bool ret = false;
str_lower = str_tolower(str);
str_lower = str_to_lower(str);
if (strcmp(str_lower, "true") == 0) {
ret = true;
}
+8 -8
View File
@@ -15,9 +15,9 @@ extern "C" {
#endif
/**
* helper to use strnlen() instead of strlen.
* Helper to use strnlen() instead of strlen.
*/
#define string_len(_str) strnlen(_str, INT64_MAX)
#define str_len(_str) strnlen(_str, INT64_MAX)
/**
* Return a new allocated string with the content printed from fmt and
@@ -50,12 +50,12 @@ char *strdup_or_die(const char *const str);
/**
* Join strings from string list separated by the separator.
*/
char *string_join(const char *separator, struct list *string);
char *str_join(const char *separator, struct list *string);
/**
* Split a string by separator.
*/
struct list *string_split(const char *separator, const char *string_to_split);
struct list *str_split(const char *separator, const char *string_to_split);
/**
* Safely convert string to integer avoiding overflows
@@ -69,7 +69,7 @@ struct list *string_split(const char *separator, const char *string_to_split);
* -EINVAL is returned when the string isn't a valid number or has any invalid
* trailing character.
*/
int strtoi_err(const char *str, int *value);
int str_to_int(const char *str, int *value);
/**
* Safely convert and string to integer avoiding overflows.
@@ -83,7 +83,7 @@ int strtoi_err(const char *str, int *value);
*
* endptr is set with the value of the first invalid character in the string.
*/
int strtoi_err_endptr(const char *str, char **endptr, int *value);
int str_to_int_endptr(const char *str, char **endptr, int *value);
/**
* Creates a new string converting all characters from the original string
@@ -93,7 +93,7 @@ int strtoi_err_endptr(const char *str, char **endptr, int *value);
*
* The memory of the new string has to be freed after using it.
*/
char *str_tolower(const char *str);
char *str_to_lower(const char *str);
/**
* Converts a string to a boolean. If the string is "true" then it is converted
@@ -101,7 +101,7 @@ char *str_tolower(const char *str);
* @note Comparission to "true" is canse insensitive.
*/
bool strtobool(const char *str);
bool str_to_bool(const char *str);
/**
* Returns a copy of str with all chars c1 replaced with c2.
+3 -3
View File
@@ -80,7 +80,7 @@ static void print_debug_run_command(char **params)
}
str = list_head(str);
output = string_join(" ", str);
output = str_join(" ", str);
list_free_list(str);
debug(output);
@@ -444,8 +444,8 @@ char *sys_path_join(const char *fmt, ...)
}
va_end(ap);
len = string_len(path);
char *pretty_path = malloc(string_len(path) + 1);
len = str_len(path);
char *pretty_path = malloc(str_len(path) + 1);
ON_NULL_ABORT(pretty_path);
/* remove all duplicated PATH_SEPARATOR from the path */
+6 -6
View File
@@ -26,8 +26,8 @@
#define MANIFEST_LINE_MAXLEN (PATH_MAX * 2)
// strncmp helper to be used with consts
#define string_len_const(_const) sizeof(_const) - 1
#define strncmp_const(_str, _const) strncmp(_str, _const, string_len_const(_const))
#define str_len_const(_const) sizeof(_const) - 1
#define strncmp_const(_str, _const) strncmp(_str, _const, str_len_const(_const))
#define MANIFEST_HEADER "MANIFEST\t"
@@ -62,8 +62,8 @@ struct manifest *manifest_parse(const char *component, const char *filename, boo
goto err_close;
}
c = line + string_len_const(MANIFEST_HEADER);
err = strtoi_err(c, &manifest->manifest_version);
c = line + str_len_const(MANIFEST_HEADER);
err = str_to_int(c, &manifest->manifest_version);
if (manifest->manifest_version <= 0 || err != 0) {
error("Loaded incompatible manifest version\n");
@@ -98,7 +98,7 @@ struct manifest *manifest_parse(const char *component, const char *filename, boo
}
if (strncmp_const(line, "version:\t") == 0) {
err = strtoi_err(c, &manifest->version);
err = str_to_int(c, &manifest->version);
if (err != 0) {
error("Invalid manifest version on %s\n", filename);
goto err_close;
@@ -235,7 +235,7 @@ struct manifest *manifest_parse(const char *component, const char *filename, boo
goto err_close;
}
err = strtoi_err(c, &file->last_change);
err = str_to_int(c, &file->last_change);
if (file->last_change <= 0 || err != 0) {
error("Loaded incompatible manifest last change\n");
free(file);
+1 -1
View File
@@ -70,7 +70,7 @@ static bool parse_opt(int opt, char *optarg)
if (strcmp("latest", optarg) == 0) {
return true;
}
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version <= 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
+2 -2
View File
@@ -83,7 +83,7 @@ static bool parse_opt(int opt, char *optarg)
switch (opt) {
case 'm':
case 'V':
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid --%s argument: %s\n\n", opt == 'V' ? "version" : "manifest", optarg);
return false;
@@ -118,7 +118,7 @@ static bool parse_opt(int opt, char *optarg)
* we need to delete the existing list first */
list_free_list(cmdline_bundles);
cmdline_bundles = NULL;
cmdline_bundles = string_split(",", optarg);
cmdline_bundles = str_split(",", optarg);
if (!cmdline_bundles) {
error("Missing required --bundles argument\n\n");
return false;
+3 -3
View File
@@ -109,7 +109,7 @@ static void run_ldconfig(void)
static void update_triggers(bool block)
{
if (string_len(POST_UPDATE) == 0) {
if (str_len(POST_UPDATE) == 0) {
/* fall back to systemd if path prefix is not the rootfs
* and the POST_UPDATE trigger wasn't specified */
if (strcmp("/", globals.path_prefix) != 0) {
@@ -171,7 +171,7 @@ void scripts_run_post_update(bool block)
static void exec_pre_update_script(const char *script)
{
if (string_len(PRE_UPDATE) == 0 || strcmp("/", globals.path_prefix) == 0) {
if (str_len(PRE_UPDATE) == 0 || strcmp("/", globals.path_prefix) == 0) {
run_script_if_exists(script, NULL);
} else {
run_script_if_exists(script, globals.path_prefix, NULL);
@@ -184,7 +184,7 @@ void scripts_run_pre_update(struct manifest *manifest)
struct file *file;
char *script;
if (string_len(PRE_UPDATE) == 0) {
if (str_len(PRE_UPDATE) == 0) {
string_or_die(&script, "/usr/bin/clr_pre_update.sh");
} else {
string_or_die(&script, "%s/%s", globals.path_prefix, PRE_UPDATE);
+4 -4
View File
@@ -243,7 +243,7 @@ static bool match_path_prefix(const char *path, const char *path_list[])
int i;
for (i = 0; path_list[i] != NULL; i++) {
if (strncmp(path, path_list[i], string_len(path_list[i])) == 0) {
if (strncmp(path, path_list[i], str_len(path_list[i])) == 0) {
return true;
}
}
@@ -424,7 +424,7 @@ static bool parse_opt(int opt, char *optarg)
switch (opt) {
case 'V':
err = strtoi_err(optarg, &cmdline_option_version);
err = str_to_int(optarg, &cmdline_option_version);
if (err < 0 || cmdline_option_version < 0) {
error("Invalid version argument: %s\n\n", optarg);
return false;
@@ -441,7 +441,7 @@ static bool parse_opt(int opt, char *optarg)
}
return true;
case 'T':
err = strtoi_err(optarg, &num_results);
err = str_to_int(optarg, &num_results);
if (err != 0) {
error("Invalid --top argument\n");
return false;
@@ -493,7 +493,7 @@ static bool parse_options(int argc, char **argv)
search_string = optind < argc ? argv[optind] : "";
/* Arbitrary upper limit to ensure we aren't getting handed garbage */
if (string_len(search_string) > PATH_MAX) {
if (str_len(search_string) > PATH_MAX) {
error("Search string is too long\n");
return false;
}
+2 -2
View File
@@ -73,10 +73,10 @@ static inline int subcmd_index(char *arg, struct subcmd *commands)
size_t input_len;
size_t cmd_len;
input_len = string_len(arg);
input_len = str_len(arg);
while (entry->name != NULL) {
cmd_len = string_len(entry->name);
cmd_len = str_len(entry->name);
if (cmd_len == input_len && strcmp(arg, entry->name) == 0) {
return i;
}
+1 -1
View File
@@ -577,7 +577,7 @@ static bool parse_opt(int opt, char *optarg)
return true;
}
err = strtoi_err(optarg, &requested_version);
err = str_to_int(optarg, &requested_version);
if (err < 0 || requested_version < 0) {
error("Invalid --version argument: %s\n\n", optarg);
return false;
+3 -3
View File
@@ -651,7 +651,7 @@ static bool parse_opt(int opt, char *optarg)
return true;
}
err = strtoi_err(optarg, &version);
err = str_to_int(optarg, &version);
if (err < 0 || version < 0) {
error("Invalid --%s argument: %s\n\n", opt == 'V' ? "version" : "manifest", optarg);
return false;
@@ -703,7 +703,7 @@ static bool parse_opt(int opt, char *optarg)
* a possible existing list parsed from a config file, we want to replace it, so
* we need to delete the existing list first */
list_free_list(cmdline_option_bundles);
cmdline_option_bundles = string_split(",", optarg);
cmdline_option_bundles = str_split(",", optarg);
if (!cmdline_option_bundles) {
error("Missing required --bundles argument\n\n");
return false;
@@ -885,7 +885,7 @@ static struct list *keep_matching_path(struct list *all_files)
for (iter = all_files; iter; iter = iter->next) {
file = iter->data;
if (strncmp(cmdline_option_file, file->filename, string_len(cmdline_option_file)) == 0) {
if (strncmp(cmdline_option_file, file->filename, str_len(cmdline_option_file)) == 0) {
/* preserving the order is important */
matching_files = list_append_data(matching_files, file);
}
+8 -8
View File
@@ -47,7 +47,7 @@ int get_int_from_url(const char *url)
}
tmp_data.data[tmp_data.len] = '\0';
err = strtoi_err(tmp_data.data, &value);
err = str_to_int(tmp_data.data, &value);
if (err != 0) {
return -1;
}
@@ -80,7 +80,7 @@ int get_current_format(void)
goto out;
}
err = strtoi_err(temp_format_buffer, &ret);
err = str_to_int(temp_format_buffer, &ret);
if (err != 0) {
goto out;
}
@@ -167,7 +167,7 @@ static int get_version_from_url(char *url)
return ret;
} else {
tmp_version.data[tmp_version.len] = '\0';
err = strtoi_err(tmp_version.data, &ret);
err = str_to_int(tmp_version.data, &ret);
if (err != 0) {
return -1;
}
@@ -252,7 +252,7 @@ static bool get_osrelease_value(char *path_prefix, char *key, char *buff)
char *releasefile = NULL;
char *src = NULL, *dest = NULL;
char *keystr = NULL;
int keystring_len = 0;
int keystr_len = 0;
bool keyfound = false;
releasefile = sys_path_join("%s/usr/lib/os-release", path_prefix);
@@ -268,15 +268,15 @@ static bool get_osrelease_value(char *path_prefix, char *key, char *buff)
}
string_or_die(&keystr, "%s=", key);
keystring_len = string_len(keystr);
keystr_len = str_len(keystr);
while (!feof(file)) {
line[0] = 0x00;
if (fgets(line, LINE_MAX, file) == NULL) {
break;
}
if (strncmp(line, keystr, keystring_len) == 0) {
if (strncmp(line, keystr, keystr_len) == 0) {
keyfound = true;
src = &line[keystring_len];
src = &line[keystr_len];
/* Drop quotes and newline in value */
dest = buff;
while (*src) {
@@ -307,7 +307,7 @@ int get_current_version(char *path_prefix)
if (!get_osrelease_value(path_prefix, "VERSION_ID", buff)) {
return -1;
}
if (strtoi_err(buff, &v) != 0) {
if (str_to_int(buff, &v) != 0) {
return -1;
}
+3 -3
View File
@@ -96,7 +96,7 @@ static int get_xattr_name_count(const char *names_list, ssize_t len)
int count = 0;
const char *name;
for (name = names_list; name < (names_list + len); name += string_len(name) + 1) {
for (name = names_list; name < (names_list + len); name += str_len(name) + 1) {
count++;
}
@@ -118,7 +118,7 @@ static const char **get_sorted_xattr_name_table(const char *names, int n)
for (i = 0; i < n; i++) {
table[i] = names;
names += string_len(names) + 1;
names += str_len(names) + 1;
}
qsort(table, n, sizeof(char *), cmp_xattr_name_ptrs);
@@ -180,7 +180,7 @@ static void xattrs_do_action(xattrs_action_type_t action,
value_len = len;
for (i = 0; i < count; i++) {
len = string_len(sorted_list[i]) + 1;
len = str_len(sorted_list[i]) + 1;
memcpy(value + offset, sorted_list[i], len);
offset += len;
}
+4 -4
View File
@@ -20,7 +20,7 @@ void test_list_sorted_deduplicate()
list = list_prepend_data(list, "A");
list = list_sorted_deduplicate(list, strcmp_wrapper, NULL);
str = string_join(", ", list);
str = str_join(", ", list);
check(strcmp("A", str) == 0);
free(str);
@@ -40,7 +40,7 @@ void test_list_sorted_deduplicate()
list = list_head(list);
list = list_sorted_deduplicate(list, strcmp_wrapper, NULL);
str = string_join(", ", list);
str = str_join(", ", list);
check(strcmp("A, B, C, D, E", str) == 0);
free(str);
list_free_list(list);
@@ -65,7 +65,7 @@ void test_list_filter_elements()
list = list_prepend_data(list, "A");
list = list_filter_elements(list, filterX, NULL);
str = string_join(", ", list);
str = str_join(", ", list);
check(strcmp("A", str) == 0);
free(str);
list_free_list(list);
@@ -110,7 +110,7 @@ void test_list_filter_elements()
list = list_head(list);
list = list_filter_elements(list, filterX, NULL);
str = string_join(", ", list);
str = str_join(", ", list);
check(strcmp("A, B, C, D, E, F", str) == 0);
free(str);
list_free_list(list);
+39 -39
View File
@@ -7,7 +7,7 @@
#include "../../src/lib/list.h"
#include "test_helper.h"
static void test_strtoi_err()
static void test_str_to_int()
{
char tmp_str[100];
int err;
@@ -20,7 +20,7 @@ static void test_strtoi_err()
for (i = 0; i < sizeof(values) / sizeof(int); i++) {
value = 0xffffff;
err = strtoi_err(str_values[i], &value);
err = str_to_int(str_values[i], &value);
check(err == 0);
check(value == values[i]);
}
@@ -28,50 +28,50 @@ static void test_strtoi_err()
// test limits
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MAX - 1);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == 0);
check(value == INT_MAX - 1);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MAX);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == 0);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MIN + 1);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == 0);
check(value == INT_MIN + 1);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MIN);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == 0);
check(value == INT_MIN);
// test errors
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MAX + 1);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == -ERANGE);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MAX + 1000);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == -ERANGE);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MIN - 1);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == -ERANGE);
check(value == INT_MIN);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MIN - 1000);
err = strtoi_err(tmp_str, &value);
err = str_to_int(tmp_str, &value);
check(err == -ERANGE);
check(value == INT_MIN);
@@ -79,12 +79,12 @@ static void test_strtoi_err()
char *einval_errors[] = { "string", "123.456", "123a", "a123a", "456b123", "0x12345", "4f"};
for (i = 0; i < sizeof(einval_errors) / sizeof(char *); i++) {
err = strtoi_err(einval_errors[i], &value);
err = str_to_int(einval_errors[i], &value);
check(err == -EINVAL);
}
}
static void test_strtoi_err_endptr()
static void test_str_to_int_endptr()
{
char tmp_str[100];
char *endptr;
@@ -98,7 +98,7 @@ static void test_strtoi_err_endptr()
for (i = 0; i < sizeof(values) / sizeof(int); i++) {
value = 0xffffff;
err = strtoi_err_endptr(str_values[i], NULL, &value);
err = str_to_int_endptr(str_values[i], NULL, &value);
check(err == 0);
check(value == values[i]);
}
@@ -106,57 +106,57 @@ static void test_strtoi_err_endptr()
// test limits
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MAX - 1);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == 0);
check(value == INT_MAX - 1);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MAX);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == 0);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MIN + 1);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == 0);
check(value == INT_MIN + 1);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%d", INT_MIN);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == 0);
check(value == INT_MIN);
// test errors
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MAX + 1);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == -ERANGE);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MAX + 1000);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == -ERANGE);
check(value == INT_MAX);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MIN - 1);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == -ERANGE);
check(value == INT_MIN);
value = 0xffffff;
snprintf(tmp_str, sizeof(tmp_str), "%ld", (long)INT_MIN - 1000);
err = strtoi_err_endptr(tmp_str, NULL, &value);
err = str_to_int_endptr(tmp_str, NULL, &value);
check(err == -ERANGE);
check(value == INT_MIN);
// Test endptr trailing chars
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("123.456", &endptr, &value);
err = str_to_int_endptr("123.456", &endptr, &value);
check(err == 0);
check(value == 123);
check(endptr != NULL);
@@ -164,7 +164,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("123a456", &endptr, &value);
err = str_to_int_endptr("123a456", &endptr, &value);
check(err == 0);
check(value == 123);
check(endptr != NULL);
@@ -172,7 +172,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("123testing456", &endptr, &value);
err = str_to_int_endptr("123testing456", &endptr, &value);
check(err == 0);
check(value == 123);
check(endptr != NULL);
@@ -180,7 +180,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("123-456", &endptr, &value);
err = str_to_int_endptr("123-456", &endptr, &value);
check(err == 0);
check(value == 123);
check(endptr != NULL);
@@ -188,7 +188,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("-123.456", &endptr, &value);
err = str_to_int_endptr("-123.456", &endptr, &value);
check(err == 0);
check(value == -123);
check(endptr != NULL);
@@ -196,7 +196,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("-123a456", &endptr, &value);
err = str_to_int_endptr("-123a456", &endptr, &value);
check(err == 0);
check(value == -123);
check(endptr != NULL);
@@ -204,7 +204,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("-123testing456", &endptr, &value);
err = str_to_int_endptr("-123testing456", &endptr, &value);
check(err == 0);
check(value == -123);
check(endptr != NULL);
@@ -212,7 +212,7 @@ static void test_strtoi_err_endptr()
value = 0xffffff;
endptr = NULL;
err = strtoi_err_endptr("-123-456", &endptr, &value);
err = str_to_int_endptr("-123-456", &endptr, &value);
check(err == 0);
check(value == -123);
check(endptr != NULL);
@@ -220,37 +220,37 @@ static void test_strtoi_err_endptr()
}
void test_string_join()
void test_str_join()
{
struct list *str_list = NULL;
char *joined;
joined = string_join(" long separator ", str_list);
joined = str_join(" long separator ", str_list);
check(strcmp(joined, "") == 0);
free(joined);
str_list = list_prepend_data(str_list, "string3");
joined = string_join(" long separator ", str_list);
joined = str_join(" long separator ", str_list);
check(strcmp(joined, "string3") == 0);
free(joined);
str_list = list_prepend_data(str_list, "string2");
str_list = list_prepend_data(str_list, "string1");
joined = string_join(",", str_list);
joined = str_join(",", str_list);
check(strcmp(joined, "string1,string2,string3") == 0);
free(joined);
joined = string_join(" long separator ", str_list);
joined = str_join(" long separator ", str_list);
check(strcmp(joined, "string1 long separator string2 long separator string3") == 0);
free(joined);
joined = string_join("", str_list);
joined = str_join("", str_list);
check(strcmp(joined, "string1string2string3") == 0);
free(joined);
joined = string_join(NULL, str_list);
joined = str_join(NULL, str_list);
check(strcmp(joined, "string1string2string3") == 0);
free(joined);
@@ -258,9 +258,9 @@ void test_string_join()
}
int main() {
test_strtoi_err();
test_strtoi_err_endptr();
test_string_join();
test_str_to_int();
test_str_to_int_endptr();
test_str_join();
return 0;
}