PageRenderTime 74ms CodeModel.GetById 21ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jansson/src/error.c

http://github.com/nicolasff/webdis
C | 38 lines | 29 code | 8 blank | 1 comment | 4 complexity | 5135d5b1fc954e596a3bb91dd5c91587 MD5 | raw file
 1#include <string.h>
 2#include <stdarg.h>
 3
 4#include "jansson_private.h"
 5
 6void jsonp_error_init(json_error_t *error, const char *source)
 7{
 8    if(error)
 9    {
10        error->text[0] = '\0';
11        error->line = -1;
12        error->column = -1;
13
14        strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
15        error->source[JSON_ERROR_SOURCE_LENGTH - 1] = '\0';
16    }
17}
18
19void jsonp_error_set(json_error_t *error, int line, int column,
20                     const char *msg, ...)
21{
22    va_list ap;
23
24    if(!error)
25        return;
26
27    if(error->text[0] != '\0') {
28        /* error already set */
29        return;
30    }
31
32    error->line = line;
33    error->column = column;
34
35    va_start(ap, msg);
36    vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
37    va_end(ap);
38}