diff --git a/src/dump.c b/src/dump.c index e5af458..9645e9f 100644 --- a/src/dump.c +++ b/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; +} diff --git a/src/jansson.h b/src/jansson.h index e90491a..9b79892 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -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 diff --git a/src/load.c b/src/load.c index 975d7e9..d28721e 100644 --- a/src/load.c +++ b/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; +} diff --git a/test/.gitignore b/test/.gitignore index 03b6f77..9a580ba 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,4 @@ -load_dump loadf_dumpf loads_dumps +load_file_dump_file testlogs diff --git a/test/Makefile.am b/test/Makefile.am index 865b1e9..16c5fd2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 diff --git a/test/load_dump.c b/test/load_file_dump_file.c similarity index 81% rename from test/load_dump.c rename to test/load_file_dump_file.c index 96995e5..5add119 100644 --- a/test/load_dump.c +++ b/test/load_file_dump_file.c @@ -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; diff --git a/test/run-test b/test/run-test index aaaf2b7..2086c82 100644 --- a/test/run-test +++ b/test/run-test @@ -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