diff options
Diffstat (limited to 'index.c')
-rw-r--r-- | index.c | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -1,17 +1,25 @@ +#include <inttypes.h> #include <stddef.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <syslog.h> #include <sys/stat.h> #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 { |