21 #include <sys/types.h> 37 # define WIN32_LEAN_AND_MEAN 42 #if !HAVE_OPEN && defined(WIN32) 61 if((fd = open(filename, O_RDONLY)) < 0) {
62 mc_error(
"json_object_from_file: error reading file %s: %s\n",
63 filename, strerror(errno));
67 mc_error(
"json_object_from_file: printbuf_new failed\n");
75 mc_abort(
"json_object_from_file: error reading file %s: %s\n",
76 filename, strerror(errno));
89 unsigned int wpos, wsize;
92 mc_error(
"json_object_to_file: object is null\n");
96 if((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) {
97 mc_error(
"json_object_to_file: error opening file %s: %s\n",
98 filename, strerror(errno));
105 wsize = (
unsigned int)(strlen(json_str) & UINT_MAX);
107 while(wpos < wsize) {
108 if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) {
110 mc_error(
"json_object_to_file: error writing file %s: %s\n",
111 filename, strerror(errno));
116 wpos += (
unsigned int)ret;
struct printbuf * printbuf_new()
void mc_error(const char *msg,...)
#define JSON_FILE_BUF_SIZE
struct json_object * json_object_from_file(char *filename)
const char * json_object_to_json_string(struct json_object *this)
void mc_abort(const char *msg,...)
void printbuf_free(struct printbuf *p)
int json_object_to_file(char *filename, struct json_object *obj)
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
struct json_object * json_tokener_parse(const char *str)