diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-09-12 13:15:54 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-09-12 13:15:54 -0300 |
commit | a087ad9e45ac64f2ae6258f729a68bcc224fe305 (patch) | |
tree | e5faa695f9f0173f73d220da332d5cbd7a8876b2 /src/common/conf.c | |
parent | 1443f47ca63972f737bd9cc0322f77dc416ff2a0 (diff) | |
download | hercules-a087ad9e45ac64f2ae6258f729a68bcc224fe305.tar.gz hercules-a087ad9e45ac64f2ae6258f729a68bcc224fe305.tar.bz2 hercules-a087ad9e45ac64f2ae6258f729a68bcc224fe305.tar.xz hercules-a087ad9e45ac64f2ae6258f729a68bcc224fe305.zip |
This is Hercules v2019.10.20r12.5_BUGGY
Diffstat (limited to 'src/common/conf.c')
-rw-r--r-- | src/common/conf.c | 30 |
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; /* */ |