summaryrefslogtreecommitdiff
path: root/index.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-07-28 20:01:03 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-07-28 20:42:46 -0300
commitd98868fa4d03659aad9ad2d858ee51e414d54ce4 (patch)
tree7e1ce8604cb6dad2949065dfe50bf4cfe80dd2e3 /index.c
parent052e06fd16f5ef161a10fc7880e32827c814bea2 (diff)
everywhere: Fix compiler errors, compiler warnings, and correct typos
Diffstat (limited to 'index.c')
-rw-r--r--index.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/index.c b/index.c
index 2ea8971..3505d73 100644
--- a/index.c
+++ b/index.c
@@ -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 {