"Fossies" - the Fresh Open Source Software Archive 
Member "jansson-2.14/src/jansson_private.h" (19 Nov 2020, 3832 Bytes) of package /linux/www/jansson-2.14.tar.bz2:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
3 *
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.
6 */
7
8 #ifndef JANSSON_PRIVATE_H
9 #define JANSSON_PRIVATE_H
10
11 #include "hashtable.h"
12 #include "jansson.h"
13 #include "jansson_private_config.h"
14 #include "strbuffer.h"
15 #include <stddef.h>
16
17 #define container_of(ptr_, type_, member_) \
18 ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
19
20 /* On some platforms, max() may already be defined */
21 #ifndef max
22 #define max(a, b) ((a) > (b) ? (a) : (b))
23 #endif
24
25 /* va_copy is a C99 feature. In C89 implementations, it's sometimes
26 available as __va_copy. If not, memcpy() should do the trick. */
27 #ifndef va_copy
28 #ifdef __va_copy
29 #define va_copy __va_copy
30 #else
31 #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list))
32 #endif
33 #endif
34
35 typedef struct {
36 json_t json;
37 hashtable_t hashtable;
38 } json_object_t;
39
40 typedef struct {
41 json_t json;
42 size_t size;
43 size_t entries;
44 json_t **table;
45 } json_array_t;
46
47 typedef struct {
48 json_t json;
49 char *value;
50 size_t length;
51 } json_string_t;
52
53 typedef struct {
54 json_t json;
55 double value;
56 } json_real_t;
57
58 typedef struct {
59 json_t json;
60 json_int_t value;
61 } json_integer_t;
62
63 #define json_to_object(json_) container_of(json_, json_object_t, json)
64 #define json_to_array(json_) container_of(json_, json_array_t, json)
65 #define json_to_string(json_) container_of(json_, json_string_t, json)
66 #define json_to_real(json_) container_of(json_, json_real_t, json)
67 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
68
69 /* Create a string by taking ownership of an existing buffer */
70 json_t *jsonp_stringn_nocheck_own(const char *value, size_t len);
71
72 /* Error message formatting */
73 void jsonp_error_init(json_error_t *error, const char *source);
74 void jsonp_error_set_source(json_error_t *error, const char *source);
75 void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
76 enum json_error_code code, const char *msg, ...);
77 void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
78 enum json_error_code code, const char *msg, va_list ap);
79
80 /* Locale independent string<->double conversions */
81 int jsonp_strtod(strbuffer_t *strbuffer, double *out);
82 int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
83
84 /* Wrappers for custom memory functions */
85 void *jsonp_malloc(size_t size) JANSSON_ATTRS((warn_unused_result));
86 void jsonp_free(void *ptr);
87 char *jsonp_strndup(const char *str, size_t length) JANSSON_ATTRS((warn_unused_result));
88 char *jsonp_strdup(const char *str) JANSSON_ATTRS((warn_unused_result));
89 char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS((warn_unused_result));
90
91 /* Circular reference check*/
92 /* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
93 #define LOOP_KEY_LEN (2 + (sizeof(json_t *) * 2) + 1)
94 int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size,
95 size_t *key_len_out);
96
97 /* Windows compatibility */
98 #if defined(_WIN32) || defined(WIN32)
99 #if defined(_MSC_VER) /* MS compiller */
100 #if (_MSC_VER < 1900) && \
101 !defined(snprintf) /* snprintf not defined yet & not introduced */
102 #define snprintf _snprintf
103 #endif
104 #if (_MSC_VER < 1500) && \
105 !defined(vsnprintf) /* vsnprintf not defined yet & not introduced */
106 #define vsnprintf(b, c, f, a) _vsnprintf(b, c, f, a)
107 #endif
108 #else /* Other Windows compiller, old definition */
109 #define snprintf _snprintf
110 #define vsnprintf _vsnprintf
111 #endif
112 #endif
113
114 #endif