From f5a3dbf8d652dbf87f9ff27b50d11f6364551a61 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 3 Aug 2023 09:02:08 +0200 Subject: Use xs_json_dump_pp() wherever possible. --- data.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 62e326c..80200d2 100644 --- a/data.c +++ b/data.c @@ -643,9 +643,7 @@ int _object_add(const char *id, const xs_dict *obj, int ow) if ((f = fopen(fn, "w")) != NULL) { flock(fileno(f), LOCK_EX); - xs *j = xs_json_dumps_pp(obj, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(obj, 4, f); fclose(f); /* does this object has a parent? */ @@ -1190,9 +1188,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg) FILE *f; if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(msg, 4); - - fwrite(j, 1, strlen(j), f); + xs_json_dump_pp(msg, 4, f); fclose(f); /* get the filename of the actor object */ @@ -1893,9 +1889,7 @@ void notify_add(snac *snac, const char *type, const char *utype, noti = xs_dict_append(noti, "objid", objid); if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(noti, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(noti, 4, f); fclose(f); } } @@ -1970,9 +1964,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) FILE *f; if ((f = fopen(tfn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(msg, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(msg, 4, f); fclose(f); rename(tfn, fn); @@ -2569,8 +2561,7 @@ void srv_archive_error(const char *prefix, const xs_str *err, if (req) { fprintf(f, "Request headers:\n"); - xs *j = xs_json_dumps_pp(req, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(req, 4, f); fprintf(f, "\n"); } @@ -2579,8 +2570,7 @@ void srv_archive_error(const char *prefix, const xs_str *err, fprintf(f, "Data:\n"); if (xs_type(data) == XSTYPE_LIST || xs_type(data) == XSTYPE_DICT) { - xs *j = xs_json_dumps_pp(data, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(data, 4, f); } else fprintf(f, "%s", data); -- cgit v1.2.3