Get rid of json_dumpfd and json_loadfd

fdopen() makes supporting separate API for file descriptors useless.
Supporting fd's also makes Jansson less portable.
This commit is contained in:
Petri Lehtinen 2009-07-13 10:31:42 +03:00
parent 1b67edb54d
commit 4c414bdd6d
7 changed files with 1 additions and 80 deletions

View File

@ -29,14 +29,6 @@ static int dump_to_file(const char *buffer, int size, void *data)
return 0; 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) static int dump_indent(uint32_t flags, int depth, dump_func dump, void *data)
{ {
if(JSON_INDENT(flags) > 0) if(JSON_INDENT(flags) > 0)
@ -268,10 +260,3 @@ int json_dumpf(const json_t *json, FILE *output, uint32_t flags)
return -1; return -1;
return dump_to_file("\n", 1, (void *)output); 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);
}

View File

@ -96,7 +96,6 @@ typedef struct {
json_t *json_load(const char *path, json_error_t *error); 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_loads(const char *input, json_error_t *error);
json_t *json_loadf(FILE *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_INDENT(n) (n & 0xFF)
#define JSON_SORT_KEYS 0x100 #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); int json_dump(const json_t *json, const char *path, uint32_t flags);
char *json_dumps(const json_t *json, 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_dumpf(const json_t *json, FILE *output, uint32_t flags);
int json_dumpfd(const json_t *json, int fd, uint32_t flags);
#endif #endif

View File

@ -553,38 +553,3 @@ out:
strbuffer_close(&strbuff); strbuffer_close(&strbuff);
return result; 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;
}

1
test/.gitignore vendored
View File

@ -1,4 +1,3 @@
load_dump load_dump
loadf_dumpf loadf_dumpf
loadfd_dumpfd
loads_dumps loads_dumps

View 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_CPPFLAGS = -I$(top_srcdir)/src
AM_CFLAGS = -Wall -Werror AM_CFLAGS = -Wall -Werror

View File

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

View File

@ -26,6 +26,5 @@ ${srcdir}/split-testfile.py $TESTFILE $TMPDIR | \
while read input output; do while read input output; do
run_test load_dump $input $output run_test load_dump $input $output
run_test loadf_dumpf $input $output run_test loadf_dumpf $input $output
run_test loadfd_dumpfd $input $output
run_test loads_dumps $input $output run_test loads_dumps $input $output
done done