From d98868fa4d03659aad9ad2d858ee51e414d54ce4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 28 Jul 2022 20:01:03 -0300 Subject: everywhere: Fix compiler errors, compiler warnings, and correct typos --- index.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'index.c') diff --git a/index.c b/index.c index 2ea8971..3505d73 100644 --- a/index.c +++ b/index.c @@ -1,17 +1,25 @@ +#include #include #include +#include #include +#include +#include #include #include "index.h" #include "macros.h" +#include "misc.h" static int index_strlen(index_t *idx) { int len = 0; /* Get the length of the index. */ for (index_t *i = idx; i != NULL; i = i->next) { const int is_last = (i->next == NULL); - const char *fmt = (i->type) "%llu" : "%s"; - len += format_len(fmt, (i->type) ? i->num : i->name) + !is_last; + if (i->type) { + len += format_len("%"PRIu64, i->num) + !is_last; + } else { + len += format_len("%s", i->name) + !is_last; + } } return len; } @@ -35,7 +43,7 @@ int is_valid_index(index_t *idx) { /* Did we get an error? */ if (err_str != NULL) { - log_reason(LOG_ERR, "Invalid index.", reason); + log_reason(LOG_ERR, "Invalid index.", err_str); if (did_alloc) { free(err_str); } @@ -62,8 +70,11 @@ char *make_index_path(const char *root, index_t *idx, int path_type) { /* Get the length of the path. */ for (index_t *i = idx; i != NULL; i = i->next) { const int is_last = (i->next == NULL); - const char *fmt = (i->type) "%llu" : "%s"; - path_len += format_len(fmt, (i->type) ? i->num : i->name) + !is_last; + if (i->type) { + path_len += format_len("%"PRIu64, i->num) + !is_last; + } else { + path_len += format_len("%s", i->name) + !is_last; + } } path = calloc(path_len+1, sizeof(char)); @@ -74,8 +85,11 @@ char *make_index_path(const char *root, index_t *idx, int path_type) { for (index_t *i = idx; i != NULL; i = i->next) { const int is_last = (i->next == NULL); const char *delm = (path_type) ? "-" : "/"; - const char *fmt = (i->type) "%llu%s" : "%s%s"; - tmp += sprintf(tmp, fmt, (i->type) ? i->num : i->name, (!is_last) ? delm : ""); + if (i->type) { + tmp += sprintf(tmp, "%"PRIu64"%s", i->num, (!is_last) ? delm : ""); + } else { + tmp += sprintf(tmp, "%s%s", i->name, (!is_last) ? delm : ""); + } } return path; @@ -88,9 +102,11 @@ char *index_to_str(index_t *idx) { /* Create the index. */ for (index_t *i = idx; i != NULL; i = i->next) { const int is_last = (i->next == NULL); - const char *fmt = (i->type) "%llu%s" : "%s%s"; - - tmp += sprintf(tmp, fmt, (i->type) ? i->num : i->name, (!is_last) ? "-" : ""); + if (i->type) { + tmp += sprintf(tmp, "%"PRIu64"%s", i->num, (!is_last) ? "-" : ""); + } else { + tmp += sprintf(tmp, "%s%s", i->name, (!is_last) ? "-" : ""); + } } return idx_str; } else { -- cgit v1.2.3-13-gbd6f