1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11/*
12 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <strings.h>
18#include <wchar.h>
19#include <sys/debug.h>
20
21#include "libnvpair.h"
22
23#define FPRINTF(fp, ...) \
24 if (fprintf(fp, __VA_ARGS__) < 0) \
25 return (-1) \
26
27/*
28 * When formatting a string for JSON output we must escape certain characters,
29 * as described in RFC4627. This applies to both member names and
30 * DATA_TYPE_STRING values.
31 *
32 * This function will only operate correctly if the following conditions are
33 * met:
--- 261 unchanged lines hidden (view full) ---
295 case DATA_TYPE_INT8_ARRAY: {
296 int8_t *val;
297 uint_t valsz, i;
298 VERIFY0(nvpair_value_int8_array(curr, &val, &valsz));
299 FPRINTF(fp, "[");
300 for (i = 0; i < valsz; i++) {
301 if (i > 0)
302 FPRINTF(fp, ",");
303 FPRINTF(fp, "%hd", val[i]);
304 }
305 FPRINTF(fp, "]");
306 break;
307 }
308
309 case DATA_TYPE_UINT16_ARRAY: {
310 uint16_t *val;
311 uint_t valsz, i;
--- 11 unchanged lines hidden (view full) ---
323 case DATA_TYPE_INT16_ARRAY: {
324 int16_t *val;
325 uint_t valsz, i;
326 VERIFY0(nvpair_value_int16_array(curr, &val, &valsz));
327 FPRINTF(fp, "[");
328 for (i = 0; i < valsz; i++) {
329 if (i > 0)
330 FPRINTF(fp, ",");
331 FPRINTF(fp, "%hhd", val[i]);
332 }
333 FPRINTF(fp, "]");
334 break;
335 }
336
337 case DATA_TYPE_UINT32_ARRAY: {
338 uint32_t *val;
339 uint_t valsz, i;
--- 62 unchanged lines hidden ---
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11/*
12 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <strings.h>
18#include <wchar.h>
19#include <sys/debug.h>
20
21#include "libnvpair.h"
22
23#define FPRINTF(fp, ...) \
24 if (fprintf(fp, __VA_ARGS__) < 0) \
25 return (-1) \
26
27/*
28 * When formatting a string for JSON output we must escape certain characters,
29 * as described in RFC4627. This applies to both member names and
30 * DATA_TYPE_STRING values.
31 *
32 * This function will only operate correctly if the following conditions are
33 * met:
--- 261 unchanged lines hidden (view full) ---
295 case DATA_TYPE_INT8_ARRAY: {
296 int8_t *val;
297 uint_t valsz, i;
298 VERIFY0(nvpair_value_int8_array(curr, &val, &valsz));
299 FPRINTF(fp, "[");
300 for (i = 0; i < valsz; i++) {
301 if (i > 0)
302 FPRINTF(fp, ",");
303 FPRINTF(fp, "%hd", val[i]);
304 }
305 FPRINTF(fp, "]");
306 break;
307 }
308
309 case DATA_TYPE_UINT16_ARRAY: {
310 uint16_t *val;
311 uint_t valsz, i;
--- 11 unchanged lines hidden (view full) ---
323 case DATA_TYPE_INT16_ARRAY: {
324 int16_t *val;
325 uint_t valsz, i;
326 VERIFY0(nvpair_value_int16_array(curr, &val, &valsz));
327 FPRINTF(fp, "[");
328 for (i = 0; i < valsz; i++) {
329 if (i > 0)
330 FPRINTF(fp, ",");
331 FPRINTF(fp, "%hhd", val[i]);
332 }
333 FPRINTF(fp, "]");
334 break;
335 }
336
337 case DATA_TYPE_UINT32_ARRAY: {
338 uint32_t *val;
339 uint_t valsz, i;
--- 62 unchanged lines hidden ---