提交 3c6494a1 编写于 作者: J jp9000

fixed a few bugs with config files, and replaced a boolean parameter with an enum

上级 e1da9099
......@@ -232,9 +232,11 @@ complete:
return CONFIG_SUCCESS;
}
int config_open(config_t *config, const char *file, bool always_open)
int config_open(config_t *config, const char *file,
enum config_open_type open_type)
{
int errorcode;
bool always_open = open_type == CONFIG_OPEN_ALWAYS;
if (!config)
return CONFIG_ERROR;
......@@ -405,7 +407,7 @@ void config_set_int(config_t config, const char *section,
{
struct dstr str;
dstr_init(&str);
dstr_printf(&str, "%dll", value);
dstr_printf(&str, "%lld", value);
config_set_item(&config->sections, section, name, str.array);
}
......@@ -414,7 +416,7 @@ void config_set_uint(config_t config, const char *section,
{
struct dstr str;
dstr_init(&str);
dstr_printf(&str, "%ull", value);
dstr_printf(&str, "%llu", value);
config_set_item(&config->sections, section, name, str.array);
}
......@@ -447,7 +449,7 @@ void config_set_default_int(config_t config, const char *section,
{
struct dstr str;
dstr_init(&str);
dstr_printf(&str, "%dll", value);
dstr_printf(&str, "%lld", value);
config_set_item(&config->defaults, section, name, str.array);
}
......@@ -456,7 +458,7 @@ void config_set_default_uint(config_t config, const char *section,
{
struct dstr str;
dstr_init(&str);
dstr_printf(&str, "%ull", value);
dstr_printf(&str, "%llu", value);
config_set_item(&config->defaults, section, name, str.array);
}
......
......@@ -40,8 +40,14 @@ typedef struct config_data *config_t;
#define CONFIG_FILENOTFOUND -1
#define CONFIG_ERROR -2
enum config_open_type {
CONFIG_OPEN_EXISTING,
CONFIG_OPEN_ALWAYS,
};
EXPORT config_t config_create(const char *file);
EXPORT int config_open(config_t *config, const char *file, bool always_open);
EXPORT int config_open(config_t *config, const char *file,
enum config_open_type open_type);
EXPORT int config_open_defaults(config_t config, const char *file);
EXPORT int config_save(config_t config);
EXPORT void config_close(config_t config);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册