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) 2014, Joyent, Inc. |
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 do { \ 25 if (fprintf(fp, __VA_ARGS__) < 0) \ 26 return (-1); \ 27 } while (0) |
28 29/* 30 * When formatting a string for JSON output we must escape certain characters, 31 * as described in RFC4627. This applies to both member names and 32 * DATA_TYPE_STRING values. 33 * 34 * This function will only operate correctly if the following conditions are 35 * met: --- 261 unchanged lines hidden (view full) --- 297 case DATA_TYPE_INT8_ARRAY: { 298 int8_t *val; 299 uint_t valsz, i; 300 VERIFY0(nvpair_value_int8_array(curr, &val, &valsz)); 301 FPRINTF(fp, "["); 302 for (i = 0; i < valsz; i++) { 303 if (i > 0) 304 FPRINTF(fp, ","); |
305 FPRINTF(fp, "%hhd", val[i]); |
306 } 307 FPRINTF(fp, "]"); 308 break; 309 } 310 311 case DATA_TYPE_UINT16_ARRAY: { 312 uint16_t *val; 313 uint_t valsz, i; --- 11 unchanged lines hidden (view full) --- 325 case DATA_TYPE_INT16_ARRAY: { 326 int16_t *val; 327 uint_t valsz, i; 328 VERIFY0(nvpair_value_int16_array(curr, &val, &valsz)); 329 FPRINTF(fp, "["); 330 for (i = 0; i < valsz; i++) { 331 if (i > 0) 332 FPRINTF(fp, ","); |
333 FPRINTF(fp, "%hd", val[i]); |
334 } 335 FPRINTF(fp, "]"); 336 break; 337 } 338 339 case DATA_TYPE_UINT32_ARRAY: { 340 uint32_t *val; 341 uint_t valsz, i; --- 62 unchanged lines hidden --- |