Add LICENSE and a copyright note to all sources
[jansson.git] / src / dump.c
index ad22acd..c00260c 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,14 +36,6 @@ static int dump_to_file(const char *buffer, int size, void *data)
     return 0;
 }
 
-static int dump_to_fd(const char *buffer, int size, void *data)
-{
-    int *fd = (int *)data;
-    if(write(*fd, buffer, size) != size)
-        return -1;
-    return 0;
-}
-
 static int dump_indent(uint32_t flags, int depth, dump_func dump, void *data)
 {
     if(JSON_INDENT(flags) > 0)
@@ -233,15 +232,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)
-{
-    FILE *output = fopen(path, "w");
-    if(!output)
-        return -1;
-
-    return json_dumpf(json, output, flags);
-}
-
 char *json_dumps(const json_t *json, uint32_t flags)
 {
     strbuffer_t strbuff;
@@ -269,9 +259,16 @@ int json_dumpf(const json_t *json, FILE *output, uint32_t flags)
     return dump_to_file("\n", 1, (void *)output);
 }
 
-int json_dumpfd(const json_t *json, int fd, uint32_t flags)
+int json_dump_file(const json_t *json, const char *path, uint32_t flags)
 {
-    if(do_dump(json, flags, 0, dump_to_fd, (void *)&fd))
+    int result;
+
+    FILE *output = fopen(path, "w");
+    if(!output)
         return -1;
-    return dump_to_fd("\n", 1, (void *)&fd);
+
+    result = json_dumpf(json, output, flags);
+
+    fclose(output);
+    return result;
 }