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;
}

2
test/.gitignore vendored
View File

@ -1,4 +1,4 @@
load_dump
loadf_dumpf
loads_dumps
load_file_dump_file
testlogs

View File

@ -1,4 +1,4 @@
check_PROGRAMS = load_dump loadf_dumpf loads_dumps
check_PROGRAMS = loadf_dumpf loads_dumps load_file_dump_file
AM_CPPFLAGS = -I$(top_srcdir)/src
AM_CFLAGS = -Wall -Werror

View File

@ -11,13 +11,13 @@ int main(int argc, char *argv[])
return 2;
}
json = json_load(argv[1], &error);
json = json_load_file(argv[1], &error);
if(!json) {
fprintf(stderr, "%d\n%s\n", error.line, error.text);
return 1;
}
json_dump(json, argv[2], 0);
json_dump_file(json, argv[2], 0);
json_decref(json);
return 0;

View File

@ -8,7 +8,7 @@ run_testprog() {
fi
case "$prog" in
load_dump)
load_file_dump_file)
$runner./$prog \
$prefix.in \
$prefix.$prog.stdout \
@ -41,9 +41,9 @@ for testfile in $TESTFILES; do
tmpdir="testlogs/`basename $testfile`"
mkdir -p $tmpdir
${srcdir}/split-testfile.py $testfile $tmpdir | while read name; do
run_test load_dump $tmpdir/$name
run_test loadf_dumpf $tmpdir/$name
run_test loads_dumps $tmpdir/$name
run_test load_file_dump_file $tmpdir/$name
echo -n '.'
done || exit 1
echo