From 7d25827001493a82a8f75cfc6a0b956164b44f05 Mon Sep 17 00:00:00 2001 From: Guilherme Menaldo Date: Tue, 1 Oct 2019 22:57:09 -0300 Subject: Dehardcodes db files base path so the db folder can be easily moved --- src/common/conf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/common/conf.c') diff --git a/src/common/conf.c b/src/common/conf.c index 0ad350057..d81a6636b 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -22,6 +22,7 @@ #include "conf.h" +#include "common/nullpo.h" // nullpo_retv #include "common/showmsg.h" // ShowError #include "common/strlib.h" // safestrncpy #include "common/utils.h" // exists @@ -32,6 +33,31 @@ static struct libconfig_interface libconfig_s; struct libconfig_interface *libconfig; +/** + * Sets the server's db_path to be used by config_format_db_path + * @param db_path path to the folder where the db files are at + */ +static void config_set_db_path(const char *db_path) +{ + nullpo_retv(db_path); + safestrncpy(libconfig->db_path, db_path, sizeof(libconfig->db_path)); +} + +/** + * Writes into path_buf the fullpath to the db file in filename. + * Basically this prepends map->db_path to filename. + * @param filename File name to format (e.g. re/item_db.conf) + * @param path_buf Where to save the path to + * @param buffer_len Maximun length of path_buf + */ +static void config_format_db_path(const char *filename, char *path_buf, int buffer_len) +{ + nullpo_retv(filename); + nullpo_retv(path_buf); + + safesnprintf(path_buf, buffer_len, "%s/%s", libconfig->db_path, filename); +} + /** * Initializes 'config' and loads a configuration file. * @@ -450,6 +476,10 @@ static int config_lookup_int64_real(const struct config_t *config, const char *f void libconfig_defaults(void) { libconfig = &libconfig_s; + snprintf(libconfig->db_path, sizeof(libconfig->db_path), "db"); + libconfig->set_db_path = config_set_db_path; + libconfig->format_db_path = config_format_db_path; + /* */ libconfig->read = config_read; libconfig->write = config_write; /* */ -- cgit v1.2.3-70-g09d2