Document and tweak json_load_callback()
Change the return value of json_load_callback_t to size_t, as it's feels more correct. The callback should return (size_t)-1 on failure. Issue #57.
This commit is contained in:
@@ -232,13 +232,13 @@ json_t *json_deep_copy(json_t *value);
|
||||
#define JSON_DISABLE_EOF_CHECK 0x2
|
||||
#define JSON_DECODE_ANY 0x4
|
||||
|
||||
typedef int (*json_load_callback_t)(void *buffer, size_t buflen, void *arg);
|
||||
typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
|
||||
|
||||
json_t *json_loads(const char *input, size_t flags, json_error_t *error);
|
||||
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error);
|
||||
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error);
|
||||
json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error);
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error);
|
||||
|
||||
|
||||
/* encoding */
|
||||
|
||||
@@ -1006,11 +1006,11 @@ static int callback_get(void *data)
|
||||
{
|
||||
char c;
|
||||
callback_data_t *stream = data;
|
||||
|
||||
|
||||
if(stream->pos >= stream->len) {
|
||||
stream->pos = 0;
|
||||
stream->len = stream->callback(stream->data, MAX_BUF_LEN, stream->arg);
|
||||
if (stream->len <=0)
|
||||
if(stream->len == 0 || stream->len == (size_t)-1)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user