Rename json_{load,dump} to json_{load,dump}_file

This commit is contained in:
Petri Lehtinen
2009-07-28 10:57:17 +03:00
parent b348519e96
commit f41e380984
7 changed files with 41 additions and 41 deletions

View File

@@ -225,20 +225,6 @@ static int do_dump(const json_t *json, uint32_t flags, int depth,
}
int json_dump(const json_t *json, const char *path, uint32_t flags)
{
int result;
FILE *output = fopen(path, "w");
if(!output)
return -1;
result = json_dumpf(json, output, flags);
fclose(output);
return result;
}
char *json_dumps(const json_t *json, uint32_t flags)
{
strbuffer_t strbuff;
@@ -265,3 +251,17 @@ int json_dumpf(const json_t *json, FILE *output, uint32_t flags)
return -1;
return dump_to_file("\n", 1, (void *)output);
}
int json_dump_file(const json_t *json, const char *path, uint32_t flags)
{
int result;
FILE *output = fopen(path, "w");
if(!output)
return -1;
result = json_dumpf(json, output, flags);
fclose(output);
return result;
}

View File

@@ -93,14 +93,14 @@ typedef struct {
int line;
} json_error_t;
json_t *json_load(const char *path, json_error_t *error);
json_t *json_loads(const char *input, json_error_t *error);
json_t *json_loadf(FILE *input, json_error_t *error);
json_t *json_load_file(const char *path, json_error_t *error);
#define JSON_INDENT(n) (n & 0xFF)
int json_dump(const json_t *json, const char *path, uint32_t flags);
char *json_dumps(const json_t *json, uint32_t flags);
int json_dumpf(const json_t *json, FILE *output, uint32_t flags);
int json_dump_file(const json_t *json, const char *path, uint32_t flags);
#endif

View File

@@ -734,25 +734,6 @@ json_t *parse_json(lex_t *lex, json_error_t *error)
return parse_value(lex, error);
}
json_t *json_load(const char *path, json_error_t *error)
{
json_t *result;
FILE *fp;
fp = fopen(path, "r");
if(!fp)
{
error_set(error, NULL, "unable to open %s: %s",
path, strerror(errno));
return NULL;
}
result = json_loadf(fp, error);
fclose(fp);
return result;
}
typedef struct
{
const char *data;
@@ -821,3 +802,22 @@ json_t *json_loadf(FILE *input, json_error_t *error)
lex_close(&lex);
return result;
}
json_t *json_load_file(const char *path, json_error_t *error)
{
json_t *result;
FILE *fp;
fp = fopen(path, "r");
if(!fp)
{
error_set(error, NULL, "unable to open %s: %s",
path, strerror(errno));
return NULL;
}
result = json_loadf(fp, error);
fclose(fp);
return result;
}