summaryrefslogtreecommitdiff
path: root/src/common/conf.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-10-20 17:43:44 +0200
committerGitHub <noreply@github.com>2019-10-20 17:43:44 +0200
commit275edef51c858e9e55934ec3af92ec19db74f3d3 (patch)
tree81c4367dfb4d51fec9c71c2a407f502a514b6a67 /src/common/conf.c
parentddd0e461fb8e451912a6aee90869023e2c2d8272 (diff)
parentbe955e59bcd950d6430189a8a23a608927665c02 (diff)
downloadhercules-275edef51c858e9e55934ec3af92ec19db74f3d3.tar.gz
hercules-275edef51c858e9e55934ec3af92ec19db74f3d3.tar.bz2
hercules-275edef51c858e9e55934ec3af92ec19db74f3d3.tar.xz
hercules-275edef51c858e9e55934ec3af92ec19db74f3d3.zip
Merge pull request #2547 from guilherme-gm/201910-dehardcode-db
Dehardcode DB files path
Diffstat (limited to 'src/common/conf.c')
-rw-r--r--src/common/conf.c30
1 files changed, 30 insertions, 0 deletions
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
@@ -33,6 +34,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.
*
* Shows error and destroys 'config' in case of failure.
@@ -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;
/* */