diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/conf.c | 30 | ||||
-rw-r--r-- | src/common/conf.h | 4 |
2 files changed, 34 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; /* */ diff --git a/src/common/conf.h b/src/common/conf.h index 66960c0ec..ccab6dc17 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -29,6 +29,10 @@ * The libconfig interface -- specially for plugins, but we enforce it throughout the core to be consistent **/ struct libconfig_interface { + char db_path[256]; + void (*set_db_path) (const char *db_path); + void (*format_db_path) (const char *filename, char *path_buf, int buffer_len); + /* */ int (*read) (struct config_t *config, FILE *stream); void (*write) (const struct config_t *config, FILE *stream); /* */ |