/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. #include "jansson_private.h"
  4. void 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. strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
  12. error->source[JSON_ERROR_SOURCE_LENGTH - 1] = '\0';
  13. }
  14. }
  15. void jsonp_error_set(json_error_t *error, int line, int column,
  16. const char *msg, ...)
  17. {
  18. va_list ap;
  19. if(!error)
  20. return;
  21. if(error->text[0] != '\0') {
  22. /* error already set */
  23. return;
  24. }
  25. error->line = line;
  26. error->column = column;
  27. va_start(ap, msg);
  28. vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
  29. va_end(ap);
  30. }