diff options
author | Kenpachi2k13 <3476227+Kenpachi2k13@users.noreply.github.com> | 2020-05-05 01:00:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 01:00:27 +0200 |
commit | 66607bfbfe197a5fec86dd1efe34a2da80929648 (patch) | |
tree | ed0e97ddc134c82067a436ea3ffd67f2f46be60b /src/common/conf.c | |
parent | 3f6b7497531f9ace331ca74d271898e938245c04 (diff) | |
parent | 944d8489f1bcca93e6b2ff06a159084f064dce12 (diff) | |
download | hercules-66607bfbfe197a5fec86dd1efe34a2da80929648.tar.gz hercules-66607bfbfe197a5fec86dd1efe34a2da80929648.tar.bz2 hercules-66607bfbfe197a5fec86dd1efe34a2da80929648.tar.xz hercules-66607bfbfe197a5fec86dd1efe34a2da80929648.zip |
Merge branch 'master' into configure_newopt
Diffstat (limited to 'src/common/conf.c')
-rw-r--r-- | src/common/conf.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/common/conf.c b/src/common/conf.c index 0ad350057..dae7db8fc 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2018 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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; /* */ |