]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/jansson/jansson_private.h
2 * Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
4 * Jansson is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
8 #ifndef JANSSON_PRIVATE_H
9 #define JANSSON_PRIVATE_H
12 #include <jansson_private_config.h>
17 #include "hashtable.h"
18 #include "strbuffer.h"
20 #define container_of(ptr_, type_, member_) \
21 ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
23 /* On some platforms, max() may already be defined */
25 #define max(a, b) ((a) > (b) ? (a) : (b))
28 /* va_copy is a C99 feature. In C89 implementations, it's sometimes
29 available as __va_copy. If not, memcpy() should do the trick. */
32 #define va_copy __va_copy
34 #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list))
40 hashtable_t hashtable
;
66 #define json_to_object(json_) container_of(json_, json_object_t, json)
67 #define json_to_array(json_) container_of(json_, json_array_t, json)
68 #define json_to_string(json_) container_of(json_, json_string_t, json)
69 #define json_to_real(json_) container_of(json_, json_real_t, json)
70 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
72 /* Create a string by taking ownership of an existing buffer */
73 json_t
*jsonp_stringn_nocheck_own(const char *value
, size_t len
);
75 /* Error message formatting */
76 void jsonp_error_init(json_error_t
*error
, const char *source
);
77 void jsonp_error_set_source(json_error_t
*error
, const char *source
);
78 void jsonp_error_set(json_error_t
*error
, int line
, int column
,
79 size_t position
, enum json_error_code code
,
80 const char *msg
, ...);
81 void jsonp_error_vset(json_error_t
*error
, int line
, int column
,
82 size_t position
, enum json_error_code code
,
83 const char *msg
, va_list ap
);
85 /* Locale independent string<->double conversions */
86 int jsonp_strtod(strbuffer_t
*strbuffer
, double *out
);
87 int jsonp_dtostr(char *buffer
, size_t size
, double value
, int prec
);
89 /* Wrappers for custom memory functions */
90 void* jsonp_malloc(size_t size
) JANSSON_ATTRS(warn_unused_result
);
91 void jsonp_free(void *ptr
);
92 char *jsonp_strndup(const char *str
, size_t length
) JANSSON_ATTRS(warn_unused_result
);
93 char *jsonp_strdup(const char *str
) JANSSON_ATTRS(warn_unused_result
);
94 char *jsonp_strndup(const char *str
, size_t len
) JANSSON_ATTRS(warn_unused_result
);
97 /* Windows compatibility */
98 #if defined(_WIN32) || defined(WIN32)
99 # if defined(_MSC_VER) /* MS compiller */
100 # if (_MSC_VER < 1900) && !defined(snprintf) /* snprintf not defined yet & not introduced */
101 # define snprintf _snprintf
103 # if (_MSC_VER < 1500) && !defined(vsnprintf) /* vsnprintf not defined yet & not introduced */
104 # define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
106 # else /* Other Windows compiller, old definition */
107 # define snprintf _snprintf
108 # define vsnprintf _vsnprintf