2 #include "jansson_private.h"
4 void jsonp_error_init(json_error_t
*error
, const char *source
) {
11 jsonp_error_set_source(error
, source
);
13 error
->source
[0] = '\0';
17 void jsonp_error_set_source(json_error_t
*error
, const char *source
) {
20 if (!error
|| !source
)
23 length
= strlen(source
);
24 if (length
< JSON_ERROR_SOURCE_LENGTH
) {
25 strncpy(error
->source
, source
, JSON_ERROR_SOURCE_LENGTH
- 1);
27 size_t extra
= length
- JSON_ERROR_SOURCE_LENGTH
+ 4;
28 memcpy(error
->source
, "...", 3);
29 strncpy(error
->source
+ 3, source
+ extra
, length
- extra
+ 1);
33 void jsonp_error_set(json_error_t
*error
, int line
, int column
,
34 size_t position
, enum json_error_code code
,
35 const char *msg
, ...) {
38 jsonp_error_vset(error
, line
, column
, position
, code
, msg
, ap
);
42 void jsonp_error_vset(json_error_t
*error
, int line
, int column
,
43 size_t position
, enum json_error_code code
,
44 const char *msg
, va_list ap
) {
48 if (error
->text
[0] != '\0') {
49 /* error already set */
54 error
->column
= column
;
55 error
->position
= (int)position
;
57 vsnprintf(error
->text
, JSON_ERROR_TEXT_LENGTH
- 1, msg
, ap
);
58 error
->text
[JSON_ERROR_TEXT_LENGTH
- 2] = '\0';
59 error
->text
[JSON_ERROR_TEXT_LENGTH
- 1] = code
;