Rename json_{load,dump} to json_{load,dump}_file
This commit is contained in:
28
src/dump.c
28
src/dump.c
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
38
src/load.c
38
src/load.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user