-
Notifications
You must be signed in to change notification settings - Fork 0
/
jprint.h
66 lines (56 loc) · 1.72 KB
/
jprint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* jprint.h
*/
/* If in ZFS <sys/zfs_context.h> provides what is needed */
/* If standalone */
#include <stdbool.h>
#define boolean_t bool
#define B_TRUE true
#define B_FALSE false
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <inttypes.h>
/*
* int64_t used because we may want to output pointers as integer.
* Careful when reading the values... json itself does not define
* numeric ranges.
*/
/* maximum stack nesting */
#define JP_MAX_STACK 32
enum jp_type {
JP_OBJECT = 1,
JP_ARRAY
};
struct jp_stack {
enum jp_type type;
int nelem;
};
typedef struct jprint {
char *buffer; /* pointer to application's buffer */
size_t buflen; /* length of buffer */
char *bufp; /* current write position in buffer */
char tmpbuf[32]; /* local buffer for conversions */
int error; /* error code */
int ncall; /* API call number on which error occurred */
struct jp_stack /* stack of array/object nodes */
stack[JP_MAX_STACK];
int stackp;
} jprint_t;
/* error return codes */
#define JPRINT_OK 0
#define JPRINT_BUF_FULL 1 /* output buffer full */
#define JPRINT_NEST_ERROR 2 /* nesting error */
#define JPRINT_STACK_FULL 3 /* array/object nesting */
#define JPRINT_STACK_EMPTY 4 /* stack underflow error */
#define JPRINT_OPEN 5 /* not all objects closed */
#define JPRINT_FMT 6 /* format error */
#define JPRINT_NO_DOUBLE 7 /* %g support not included */
const char *jp_errorstring(int err);
int jp_error(jprint_t *jp);
void jp_open(jprint_t *jp, char *buffer, size_t buflen);
int jp_close(jprint_t *jp);
int jp_errorpos(jprint_t *jp);
int jp_printf(jprint_t *jp, const char *fmt, ...);