nvpair_json.c (260710) | nvpair_json.c (275552) |
---|---|
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/* | 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. | 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 | 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) \ | 23#define FPRINTF(fp, ...) \ 24 do { \ 25 if (fprintf(fp, __VA_ARGS__) < 0) \ 26 return (-1); \ 27 } while (0) |
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, ","); | 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, ","); |
303 FPRINTF(fp, "%hd", val[i]); | 305 FPRINTF(fp, "%hhd", 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, ","); | 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, ","); |
331 FPRINTF(fp, "%hhd", val[i]); | 333 FPRINTF(fp, "%hd", 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 --- | 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 --- |