Get rid of json_dumpfd and json_loadfd
authorPetri Lehtinen <petri@digip.org>
Mon, 13 Jul 2009 07:31:42 +0000 (10:31 +0300)
committerPetri Lehtinen <petri@digip.org>
Mon, 13 Jul 2009 18:45:16 +0000 (21:45 +0300)
fdopen() makes supporting separate API for file descriptors useless.
Supporting fd's also makes Jansson less portable.

src/dump.c
src/jansson.h
src/load.c
test/.gitignore
test/Makefile.am
test/loadfd_dumpfd.c [deleted file]
test/run-test

index ad22acd..fff931a 100644 (file)
@@ -29,14 +29,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)
@@ -268,10 +260,3 @@ int json_dumpf(const json_t *json, FILE *output, uint32_t flags)
         return -1;
     return dump_to_file("\n", 1, (void *)output);
 }
-
-int json_dumpfd(const json_t *json, int fd, uint32_t flags)
-{
-    if(do_dump(json, flags, 0, dump_to_fd, (void *)&fd))
-        return -1;
-    return dump_to_fd("\n", 1, (void *)&fd);
-}
index 395f479..33b2f94 100644 (file)
@@ -96,7 +96,6 @@ typedef struct {
 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_loadfd(int fd, json_error_t *error);
 
 #define JSON_INDENT(n)   (n & 0xFF)
 #define JSON_SORT_KEYS   0x100
@@ -104,6 +103,5 @@ json_t *json_loadfd(int fd, json_error_t *error);
 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_dumpfd(const json_t *json, int fd, uint32_t flags);
 
 #endif
index d0671bf..bd6bac6 100644 (file)
@@ -553,38 +553,3 @@ out:
     strbuffer_close(&strbuff);
     return result;
 }
-
-json_t *json_loadfd(int fd, json_error_t *error)
-{
-    strbuffer_t strbuff;
-    char buffer[BUFFER_SIZE];
-    ssize_t length;
-    json_t *result = NULL;
-
-    if(strbuffer_init(&strbuff))
-      return NULL;
-
-    while(1)
-    {
-        length = read(fd, buffer, BUFFER_SIZE);
-        if(length == -1)
-        {
-            error_set(error, NULL, "read error: %s", strerror(errno));
-            goto out;
-        }
-        else if(length == 0)
-            break;
-
-        if(strbuffer_append_bytes(&strbuff, buffer, length))
-        {
-            error_set(error, NULL, "error allocating memory");
-            goto out;
-        }
-    }
-
-    result = json_loads(strbuffer_value(&strbuff), error);
-
-out:
-    strbuffer_close(&strbuff);
-    return result;
-}
index 5147f3a..ede052b 100644 (file)
@@ -1,4 +1,3 @@
 load_dump
 loadf_dumpf
-loadfd_dumpfd
 loads_dumps
index 132c133..188fb97 100644 (file)
@@ -1,4 +1,4 @@
-check_PROGRAMS = load_dump loadf_dumpf loadfd_dumpfd loads_dumps
+check_PROGRAMS = load_dump loadf_dumpf loads_dumps
 
 AM_CPPFLAGS = -I$(top_srcdir)/src
 AM_CFLAGS = -Wall -Werror
diff --git a/test/loadfd_dumpfd.c b/test/loadfd_dumpfd.c
deleted file mode 100644 (file)
index 0faf0c6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <jansson.h>
-
-int main(int argc, char *argv[])
-{
-    json_t *json;
-    json_error_t error;
-
-    if(argc != 1) {
-        fprintf(stderr, "usage: %s\n", argv[0]);
-        return 2;
-    }
-
-    json = json_loadfd(STDIN_FILENO, &error);
-    if(!json) {
-        fprintf(stderr, "%d\n%s\n", error.line, error.text);
-        return 1;
-    }
-
-    json_dumpfd(json, STDOUT_FILENO, 0);
-    json_decref(json);
-
-    return 0;
-}
index 79d955a..c0db36a 100644 (file)
@@ -26,6 +26,5 @@ ${srcdir}/split-testfile.py $TESTFILE $TMPDIR | \
 while read input output; do
     run_test load_dump $input $output
     run_test loadf_dumpf $input $output
-    run_test loadfd_dumpfd $input $output
     run_test loads_dumps $input $output
 done