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;