Use a common variable to define the loom prefix

This commit is contained in:
Rodrigo Arias 2023-03-13 11:41:17 +01:00 committed by Rodrigo Arias Mallo
parent 411ea962ff
commit 7fba5cbdcc

View File

@ -10,11 +10,13 @@
#include "uthash.h" #include "uthash.h"
#include "utlist.h" #include "utlist.h"
static const char *loom_prefix = "loom.";
static void static void
set_hostname(char host[PATH_MAX], const char name[PATH_MAX]) set_hostname(char host[PATH_MAX], const char name[PATH_MAX])
{ {
/* Skip prefix */ /* Skip prefix */
const char *start = name + strlen("loom."); const char *start = name + strlen(loom_prefix);
/* Copy until dot or end */ /* Copy until dot or end */
int i; int i;
@ -40,7 +42,7 @@ has_prefix(const char *path, const char *prefix)
int int
loom_matches(const char *path) loom_matches(const char *path)
{ {
return has_prefix(path, "loom."); return has_prefix(path, loom_prefix);
} }
int int
@ -48,9 +50,8 @@ loom_init_begin(struct loom *loom, const char *name)
{ {
memset(loom, 0, sizeof(struct loom)); memset(loom, 0, sizeof(struct loom));
char prefix[] = "loom."; if (!has_prefix(name, loom_prefix)) {
if (!has_prefix(name, prefix)) { err("loom name must start with '%s': %s", loom_prefix, name);
err("loom name must start with '%s': %s", prefix, name);
return -1; return -1;
} }