mirror of
https://github.com/json-c/json-c.git
synced 2026-03-23 23:19:06 +08:00
Issue #161: add a json_object_to_fd() function.
This commit is contained in:
@@ -49,6 +49,25 @@ static void test_write_to_file()
|
||||
(rv == 0) ? "OK" : "FAIL", outfile2, rv);
|
||||
if (rv == 0)
|
||||
stat_and_cat(outfile2);
|
||||
|
||||
const char *outfile3 = "json3.out";
|
||||
int d = open(outfile3, O_WRONLY|O_CREAT, 0600);
|
||||
if (d < 0)
|
||||
{
|
||||
printf("FAIL: unable to open %s %s\n", outfile3, strerror(errno));
|
||||
return;
|
||||
}
|
||||
rv = json_object_to_fd(d, jso, JSON_C_TO_STRING_PRETTY);
|
||||
printf("%s: json_object_to_fd(%s, jso, JSON_C_TO_STRING_PRETTY)=%d\n",
|
||||
(rv == 0) ? "OK" : "FAIL", outfile3, rv);
|
||||
// Write the same object twice
|
||||
rv = json_object_to_fd(d, jso, JSON_C_TO_STRING_PLAIN);
|
||||
printf("%s: json_object_to_fd(%s, jso, JSON_C_TO_STRING_PLAIN)=%d\n",
|
||||
(rv == 0) ? "OK" : "FAIL", outfile3, rv);
|
||||
close(d);
|
||||
if (rv == 0)
|
||||
stat_and_cat(outfile3);
|
||||
|
||||
json_object_put(jso);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,3 +19,17 @@ file[json2.out], size=367, contents={
|
||||
"foo8":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo9":"abcdefghijklmnopqrstuvwxyz"
|
||||
}
|
||||
OK: json_object_to_fd(json3.out, jso, JSON_C_TO_STRING_PRETTY)=0
|
||||
OK: json_object_to_fd(json3.out, jso, JSON_C_TO_STRING_PLAIN)=0
|
||||
file[json3.out], size=703, contents={
|
||||
"foo":1234,
|
||||
"foo1":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo2":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo3":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo4":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo5":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo6":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo7":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo8":"abcdefghijklmnopqrstuvwxyz",
|
||||
"foo9":"abcdefghijklmnopqrstuvwxyz"
|
||||
}{"foo":1234,"foo1":"abcdefghijklmnopqrstuvwxyz","foo2":"abcdefghijklmnopqrstuvwxyz","foo3":"abcdefghijklmnopqrstuvwxyz","foo4":"abcdefghijklmnopqrstuvwxyz","foo5":"abcdefghijklmnopqrstuvwxyz","foo6":"abcdefghijklmnopqrstuvwxyz","foo7":"abcdefghijklmnopqrstuvwxyz","foo8":"abcdefghijklmnopqrstuvwxyz","foo9":"abcdefghijklmnopqrstuvwxyz"}
|
||||
|
||||
Reference in New Issue
Block a user