| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Simple streaming JSON writer |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * This takes care of the annoying bits of JSON syntax like the commas |
|---|
| 5 | 6 | * after elements |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License |
|---|
| 9 | | - * as published by the Free Software Foundation; either version |
|---|
| 10 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 11 | 7 | * |
|---|
| 12 | 8 | * Authors: Stephen Hemminger <stephen@networkplumber.org> |
|---|
| 13 | 9 | */ |
|---|
| .. | .. |
|---|
| 18 | 14 | #include <stdbool.h> |
|---|
| 19 | 15 | #include <stdint.h> |
|---|
| 20 | 16 | #include <stdarg.h> |
|---|
| 17 | +#include <linux/compiler.h> |
|---|
| 21 | 18 | |
|---|
| 22 | 19 | /* Opaque class structure */ |
|---|
| 23 | 20 | typedef struct json_writer json_writer_t; |
|---|
| .. | .. |
|---|
| 30 | 27 | /* Cause output to have pretty whitespace */ |
|---|
| 31 | 28 | void jsonw_pretty(json_writer_t *self, bool on); |
|---|
| 32 | 29 | |
|---|
| 30 | +/* Reset separator to create new JSON */ |
|---|
| 31 | +void jsonw_reset(json_writer_t *self); |
|---|
| 32 | + |
|---|
| 33 | 33 | /* Add property name */ |
|---|
| 34 | 34 | void jsonw_name(json_writer_t *self, const char *name); |
|---|
| 35 | 35 | |
|---|
| 36 | 36 | /* Add value */ |
|---|
| 37 | | -void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap); |
|---|
| 38 | | -void jsonw_printf(json_writer_t *self, const char *fmt, ...); |
|---|
| 37 | +void __printf(2, 0) jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, |
|---|
| 38 | + va_list ap); |
|---|
| 39 | +void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...); |
|---|
| 39 | 40 | void jsonw_string(json_writer_t *self, const char *value); |
|---|
| 40 | 41 | void jsonw_bool(json_writer_t *self, bool value); |
|---|
| 41 | 42 | void jsonw_float(json_writer_t *self, double number); |
|---|