Browse Source

Rename _set_last_err() to _json_c_set_last_err().

tags/json-c-0.13-20171207
Eric Haszlakiewicz 7 years ago
parent
commit
437716c5b4
4 changed files with 14 additions and 14 deletions
  1. +2
    -2
      json_object.c
  2. +1
    -1
      json_object_private.h
  3. +9
    -9
      json_util.c
  4. +2
    -2
      json_util.h

+ 2
- 2
json_object.c View File

@@ -756,13 +756,13 @@ int json_c_set_serialization_double_format(const char *double_format, int global
} }
tls_serialization_float_format = double_format ? strdup(double_format) : NULL; tls_serialization_float_format = double_format ? strdup(double_format) : NULL;
#else #else
_set_last_err("json_c_set_option: not compiled with __thread support\n");
_json_c_set_last_err("json_c_set_option: not compiled with __thread support\n");
return -1; return -1;
#endif #endif
} }
else else
{ {
_set_last_err("json_c_set_option: invalid global_or_thread value: %d\n", global_or_thread);
_json_c_set_last_err("json_c_set_option: invalid global_or_thread value: %d\n", global_or_thread);
return -1; return -1;
} }
return 0; return 0;


+ 1
- 1
json_object_private.h View File

@@ -48,7 +48,7 @@ struct json_object
void *_userdata; void *_userdata;
}; };


void _set_last_err(const char *err_fmt, ...);
void _json_c_set_last_err(const char *err_fmt, ...);


#ifdef __cplusplus #ifdef __cplusplus
} }


+ 9
- 9
json_util.c View File

@@ -72,7 +72,7 @@ const char *json_util_get_last_err()
return _last_err; return _last_err;
} }


void _set_last_err(const char *err_fmt, ...)
void _json_c_set_last_err(const char *err_fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, err_fmt); va_start(ap, err_fmt);
@@ -89,14 +89,14 @@ struct json_object* json_object_from_fd(int fd)
int ret; int ret;


if(!(pb = printbuf_new())) { if(!(pb = printbuf_new())) {
_set_last_err("json_object_from_file: printbuf_new failed\n");
_json_c_set_last_err("json_object_from_file: printbuf_new failed\n");
return NULL; return NULL;
} }
while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) { while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
printbuf_memappend(pb, buf, ret); printbuf_memappend(pb, buf, ret);
} }
if(ret < 0) { if(ret < 0) {
_set_last_err("json_object_from_fd: error reading fd %d: %s\n", fd, strerror(errno));
_json_c_set_last_err("json_object_from_fd: error reading fd %d: %s\n", fd, strerror(errno));
printbuf_free(pb); printbuf_free(pb);
return NULL; return NULL;
} }
@@ -111,7 +111,7 @@ struct json_object* json_object_from_file(const char *filename)
int fd; int fd;


if((fd = open(filename, O_RDONLY)) < 0) { if((fd = open(filename, O_RDONLY)) < 0) {
_set_last_err("json_object_from_file: error opening file %s: %s\n",
_json_c_set_last_err("json_object_from_file: error opening file %s: %s\n",
filename, strerror(errno)); filename, strerror(errno));
return NULL; return NULL;
} }
@@ -128,12 +128,12 @@ int json_object_to_file_ext(const char *filename, struct json_object *obj, int f
int saved_errno; int saved_errno;


if (!obj) { if (!obj) {
_set_last_err("json_object_to_file: object is null\n");
_json_c_set_last_err("json_object_to_file: object is null\n");
return -1; return -1;
} }


if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) { if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) {
_set_last_err("json_object_to_file: error opening file %s: %s\n",
_json_c_set_last_err("json_object_to_file: error opening file %s: %s\n",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@@ -147,7 +147,7 @@ int json_object_to_file_ext(const char *filename, struct json_object *obj, int f
int json_object_to_fd(int fd, struct json_object *obj, int flags) int json_object_to_fd(int fd, struct json_object *obj, int flags)
{ {
if (!obj) { if (!obj) {
_set_last_err("json_object_to_fd: object is null\n");
_json_c_set_last_err("json_object_to_fd: object is null\n");
return -1; return -1;
} }


@@ -169,7 +169,7 @@ static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const
wpos = 0; wpos = 0;
while(wpos < wsize) { while(wpos < wsize) {
if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) { if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) {
_set_last_err("json_object_to_file: error writing file %s: %s\n",
_json_c_set_last_err("json_object_to_file: error writing file %s: %s\n",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@@ -235,7 +235,7 @@ const char *json_type_to_name(enum json_type o_type)
int o_type_int = (int)o_type; int o_type_int = (int)o_type;
if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name)) if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name))
{ {
_set_last_err("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name));
_json_c_set_last_err("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name));
return NULL; return NULL;
} }
return json_type_name[o_type]; return json_type_name[o_type];


+ 2
- 2
json_util.h View File

@@ -77,8 +77,8 @@ extern int json_object_to_file_ext(const char *filename, struct json_object *obj
extern int json_object_to_fd(int fd, struct json_object *obj, int flags); extern int json_object_to_fd(int fd, struct json_object *obj, int flags);


/** /**
* Return the last error from json_object_to_file{,_ext},
* json_object_to_fd() or
* Return the last error from various json-c functions, including:
* json_object_to_file{,_ext}, json_object_to_fd() or
* json_object_from_{file,fd}, or NULL if there is none. * json_object_from_{file,fd}, or NULL if there is none.
*/ */
const char *json_util_get_last_err(void); const char *json_util_get_last_err(void);


Loading…
Cancel
Save