]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/jansson/error.c
fix 'hf iclass sim':
[proxmark3-svn] / client / jansson / error.c
CommitLineData
556826b5
OM
1#include <string.h>
2#include "jansson_private.h"
3
4void jsonp_error_init(json_error_t *error, const char *source)
5{
6 if(error)
7 {
8 error->text[0] = '\0';
9 error->line = -1;
10 error->column = -1;
11 error->position = 0;
12 if(source)
13 jsonp_error_set_source(error, source);
14 else
15 error->source[0] = '\0';
16 }
17}
18
19void jsonp_error_set_source(json_error_t *error, const char *source)
20{
21 size_t length;
22
23 if(!error || !source)
24 return;
25
26 length = strlen(source);
27 if(length < JSON_ERROR_SOURCE_LENGTH)
a7e1b46d 28 strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
556826b5
OM
29 else {
30 size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
a7e1b46d 31 memcpy(error->source, "...", 3);
556826b5
OM
32 strncpy(error->source + 3, source + extra, length - extra + 1);
33 }
34}
35
36void jsonp_error_set(json_error_t *error, int line, int column,
37 size_t position, enum json_error_code code,
38 const char *msg, ...)
39{
40 va_list ap;
41
42 va_start(ap, msg);
43 jsonp_error_vset(error, line, column, position, code, msg, ap);
44 va_end(ap);
45}
46
47void jsonp_error_vset(json_error_t *error, int line, int column,
48 size_t position, enum json_error_code code,
49 const char *msg, va_list ap)
50{
51 if(!error)
52 return;
53
54 if(error->text[0] != '\0') {
55 /* error already set */
56 return;
57 }
58
59 error->line = line;
60 error->column = column;
61 error->position = (int)position;
62
63 vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH - 1, msg, ap);
64 error->text[JSON_ERROR_TEXT_LENGTH - 2] = '\0';
65 error->text[JSON_ERROR_TEXT_LENGTH - 1] = code;
66}
Impressum, Datenschutz