summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-11-19 18:39:24 +0100
committerHaru <haru@dotalux.com>2016-11-19 21:08:11 +0100
commit564cf8ec2d295ccec0791f21031be7a93c78bef9 (patch)
tree766d830fdb2a2045638dab7b2df60421f7547654
parentddd36bc9c37f0ee946441b953bb2bd89cbe70b2e (diff)
downloadhercules-564cf8ec2d295ccec0791f21031be7a93c78bef9.tar.gz
hercules-564cf8ec2d295ccec0791f21031be7a93c78bef9.tar.bz2
hercules-564cf8ec2d295ccec0791f21031be7a93c78bef9.tar.xz
hercules-564cf8ec2d295ccec0791f21031be7a93c78bef9.zip
Add fixed-size versions of the _int64 libconfig getters/setters
As we use int64 (instead of long long int) through the code, it's preferable if our libconfig interface does the same, avoiding us to create temporary interchange variables for that purpose. Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/char/char.c2
-rw-r--r--src/common/conf.c86
-rw-r--r--src/common/conf.h14
-rw-r--r--src/test/test_libconfig.c6
4 files changed, 91 insertions, 17 deletions
diff --git a/src/char/char.c b/src/char/char.c
index a43f783b5..d69ea0d53 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -5940,7 +5940,7 @@ bool char_config_read_player_new(const char *filename, const struct config_t *co
#else
const char *start_point_setting = "start_point_pre";
#endif
- long long int i64 = 0; // TODO: Temporary until the signature of libconfig->setting_lookup_int64 is changed to take a defined-size int (int64)
+ int64 i64 = 0;
nullpo_retr(false, filename);
nullpo_retr(false, config);
diff --git a/src/common/conf.c b/src/common/conf.c
index 8ec2f3fb4..96b9bff9f 100644
--- a/src/common/conf.c
+++ b/src/common/conf.c
@@ -373,6 +373,80 @@ int config_lookup_mutable_string(const struct config_t *config, const char *name
return CONFIG_FALSE;
}
+/**
+ * Wrapper for config_setting_get_int64() using defined-size variables
+ *
+ * @see config_setting_get_int64_real()
+ */
+int64 config_setting_get_int64_real(const struct config_setting_t *setting)
+{
+ return (int64)config_setting_get_int64(setting);
+}
+
+/**
+ * Wrapper for config_setting_lookup_int64() using defined-size variables
+ *
+ * @see config_setting_lookup_int64()
+ */
+int config_setting_lookup_int64_real(const struct config_setting_t *setting, const char *name, int64 *value)
+{
+ long long int lli = 0;
+
+ if (config_setting_lookup_int64(setting, name, &lli) != CONFIG_TRUE)
+ return CONFIG_FALSE;
+
+ *value = (int64)lli;
+
+ return CONFIG_TRUE;
+}
+
+/**
+ * Wrapper for config_setting_set_int64() using defined-size variables
+ *
+ * @see config_setting_set_int64()
+ */
+int config_setting_set_int64_real(struct config_setting_t *setting, int64 value)
+{
+ return config_setting_set_int64(setting, (long long int)value);
+}
+
+/**
+ * Wrapper for config_setting_get_int64_elem() using defined-size variables
+ *
+ * @see config_setting_get_int64_elem()
+ */
+int64 config_setting_get_int64_elem_real(const struct config_setting_t *setting, int idx)
+{
+ return (int64)config_setting_get_int64_elem(setting, idx);
+}
+
+/**
+ * Wrapper for config_setting_set_int64_elem() using defined-size variables
+ *
+ * @see config_setting_set_int64_elem()
+ */
+struct config_setting_t *config_setting_set_int64_elem_real(struct config_setting_t *setting, int idx, int64 value)
+{
+ return config_setting_set_int64_elem(setting, idx, (long long int)value);
+}
+
+/**
+ * Wrapper for config_lookup_int64() using defined-size variables
+ *
+ * @see config_lookup_int64()
+ */
+int config_lookup_int64_real(const struct config_t *config, const char *filepath, int64 *value)
+{
+ long long int lli = 0;
+
+ if (config_lookup_int64(config, filepath, &lli) != CONFIG_TRUE)
+ return CONFIG_FALSE;
+
+ *value = (int64)lli;
+
+ return CONFIG_TRUE;
+}
+
void libconfig_defaults(void) {
libconfig = &libconfig_s;
@@ -393,20 +467,20 @@ void libconfig_defaults(void) {
libconfig->destroy = config_destroy;
/* */
libconfig->setting_get_int = config_setting_get_int;
- libconfig->setting_get_int64 = config_setting_get_int64;
+ libconfig->setting_get_int64 = config_setting_get_int64_real;
libconfig->setting_get_float = config_setting_get_float;
libconfig->setting_get_bool = config_setting_get_bool;
libconfig->setting_get_string = config_setting_get_string;
/* */
libconfig->setting_lookup = config_setting_lookup;
libconfig->setting_lookup_int = config_setting_lookup_int;
- libconfig->setting_lookup_int64 = config_setting_lookup_int64;
+ libconfig->setting_lookup_int64 = config_setting_lookup_int64_real;
libconfig->setting_lookup_float = config_setting_lookup_float;
libconfig->setting_lookup_bool = config_setting_lookup_bool;
libconfig->setting_lookup_string = config_setting_lookup_string;
/* */
libconfig->setting_set_int = config_setting_set_int;
- libconfig->setting_set_int64 = config_setting_set_int64;
+ libconfig->setting_set_int64 = config_setting_set_int64_real;
libconfig->setting_set_float = config_setting_set_float;
libconfig->setting_set_bool = config_setting_set_bool;
libconfig->setting_set_string = config_setting_set_string;
@@ -415,13 +489,13 @@ void libconfig_defaults(void) {
libconfig->setting_get_format = config_setting_get_format;
/* */
libconfig->setting_get_int_elem = config_setting_get_int_elem;
- libconfig->setting_get_int64_elem = config_setting_get_int64_elem;
+ libconfig->setting_get_int64_elem = config_setting_get_int64_elem_real;
libconfig->setting_get_float_elem = config_setting_get_float_elem;
libconfig->setting_get_bool_elem = config_setting_get_bool_elem;
libconfig->setting_get_string_elem = config_setting_get_string_elem;
/* */
libconfig->setting_set_int_elem = config_setting_set_int_elem;
- libconfig->setting_set_int64_elem = config_setting_set_int64_elem;
+ libconfig->setting_set_int64_elem = config_setting_set_int64_elem_real;
libconfig->setting_set_float_elem = config_setting_set_float_elem;
libconfig->setting_set_bool_elem = config_setting_set_bool_elem;
libconfig->setting_set_string_elem = config_setting_set_string_elem;
@@ -441,7 +515,7 @@ void libconfig_defaults(void) {
libconfig->lookup = config_lookup;
/* */
libconfig->lookup_int = config_lookup_int;
- libconfig->lookup_int64 = config_lookup_int64;
+ libconfig->lookup_int64 = config_lookup_int64_real;
libconfig->lookup_float = config_lookup_float;
libconfig->lookup_bool = config_lookup_bool;
libconfig->lookup_string = config_lookup_string;
diff --git a/src/common/conf.h b/src/common/conf.h
index cb1ca6bee..bd6acc4be 100644
--- a/src/common/conf.h
+++ b/src/common/conf.h
@@ -46,7 +46,7 @@ struct libconfig_interface {
void (*destroy) (struct config_t *config);
int (*setting_get_int) (const struct config_setting_t *setting);
- long long (*setting_get_int64) (const struct config_setting_t *setting);
+ int64 (*setting_get_int64) (const struct config_setting_t *setting);
double (*setting_get_float) (const struct config_setting_t *setting);
int (*setting_get_bool) (const struct config_setting_t *setting);
@@ -55,12 +55,12 @@ struct libconfig_interface {
struct config_setting_t * (*setting_lookup) (struct config_setting_t *setting, const char *name);
int (*setting_lookup_int) (const struct config_setting_t *setting, const char *name, int *value);
- int (*setting_lookup_int64) (const struct config_setting_t *setting, const char *name, long long *value);
+ int (*setting_lookup_int64) (const struct config_setting_t *setting, const char *name, int64 *value);
int (*setting_lookup_float) (const struct config_setting_t *setting, const char *name, double *value);
int (*setting_lookup_bool) (const struct config_setting_t *setting, const char *name, int *value);
int (*setting_lookup_string) (const struct config_setting_t *setting, const char *name, const char **value);
- int (*setting_set_int) (struct config_setting_t *setting ,int value);
- int (*setting_set_int64) (struct config_setting_t *setting, long long value);
+ int (*setting_set_int) (struct config_setting_t *setting, int value);
+ int (*setting_set_int64) (struct config_setting_t *setting, int64 value);
int (*setting_set_float) (struct config_setting_t *setting, double value);
int (*setting_set_bool) (struct config_setting_t *setting, int value);
int (*setting_set_string) (struct config_setting_t *setting, const char *value);
@@ -69,12 +69,12 @@ struct libconfig_interface {
short (*setting_get_format) (const struct config_setting_t *setting);
int (*setting_get_int_elem) (const struct config_setting_t *setting, int idx);
- long long (*setting_get_int64_elem) (const struct config_setting_t *setting, int idx);
+ int64 (*setting_get_int64_elem) (const struct config_setting_t *setting, int idx);
double (*setting_get_float_elem) (const struct config_setting_t *setting, int idx);
int (*setting_get_bool_elem) (const struct config_setting_t *setting, int idx);
const char * (*setting_get_string_elem) (const struct config_setting_t *setting, int idx);
struct config_setting_t * (*setting_set_int_elem) (struct config_setting_t *setting, int idx, int value);
- struct config_setting_t * (*setting_set_int64_elem) (struct config_setting_t *setting, int idx, long long value);
+ struct config_setting_t * (*setting_set_int64_elem) (struct config_setting_t *setting, int idx, int64 value);
struct config_setting_t * (*setting_set_float_elem) (struct config_setting_t *setting, int idx, double value);
struct config_setting_t * (*setting_set_bool_elem) (struct config_setting_t *setting, int idx, int value);
struct config_setting_t * (*setting_set_string_elem) (struct config_setting_t *setting, int idx, const char *value);
@@ -93,7 +93,7 @@ struct libconfig_interface {
struct config_setting_t * (*lookup) (const struct config_t *config, const char *filepath);
int (*lookup_int) (const struct config_t *config, const char *filepath, int *value);
- int (*lookup_int64) (const struct config_t *config, const char *filepath, long long *value);
+ int (*lookup_int64) (const struct config_t *config, const char *filepath, int64 *value);
int (*lookup_float) (const struct config_t *config, const char *filepath, double *value);
int (*lookup_bool) (const struct config_t *config, const char *filepath, int *value);
int (*lookup_string) (const struct config_t *config, const char *filepath, const char **value);
diff --git a/src/test/test_libconfig.c b/src/test/test_libconfig.c
index e0a470e21..73466ec2b 100644
--- a/src/test/test_libconfig.c
+++ b/src/test/test_libconfig.c
@@ -366,8 +366,8 @@ static const char *test_libconfig_setting_get(void)
static const char *test_libconfig_set(void)
{
- //int (*setting_set_int) (struct config_setting_t *setting ,int value);
- //int (*setting_set_int64) (struct config_setting_t *setting, long long value);
+ //int (*setting_set_int) (struct config_setting_t *setting, int value);
+ //int (*setting_set_int64) (struct config_setting_t *setting, int64 value);
//int (*setting_set_float) (struct config_setting_t *setting, double value);
//int (*setting_set_bool) (struct config_setting_t *setting, int value);
//int (*setting_set_string) (struct config_setting_t *setting, const char *value);
@@ -818,7 +818,7 @@ int do_init(int argc, char **argv)
//int (*setting_set_format) (struct config_setting_t *setting, short format);
//short (*setting_get_format) (const struct config_setting_t *setting);
//struct config_setting_t * (*setting_set_int_elem) (struct config_setting_t *setting, int idx, int value);
- //struct config_setting_t * (*setting_set_int64_elem) (struct config_setting_t *setting, int idx, long long value);
+ //struct config_setting_t * (*setting_set_int64_elem) (struct config_setting_t *setting, int idx, int64 value);
//struct config_setting_t * (*setting_set_float_elem) (struct config_setting_t *setting, int idx, double value);
//struct config_setting_t * (*setting_set_bool_elem) (struct config_setting_t *setting, int idx, int value);
//struct config_setting_t * (*setting_set_string_elem) (struct config_setting_t *setting, int idx, const char *value);