Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 1 | /* |
Michael Clark | 837240f | 2007-03-13 08:26:25 +0000 | [diff] [blame] | 2 | * $Id: json_util.c,v 1.4 2006/01/30 23:07:57 mclark Exp $ |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 3 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 5 | * Michael Clark <michael@metaparadigm.com> |
| 6 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the MIT license. See COPYING for details. |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include "config.h" |
ehaszla | 252669c | 2010-12-07 18:15:35 +0000 | [diff] [blame] | 13 | #undef realloc |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 14 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
Michael Clark | c8f4a6e | 2007-12-07 02:44:24 +0000 | [diff] [blame] | 17 | #include <stddef.h> |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 18 | #include <limits.h> |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <errno.h> |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 21 | #include <ctype.h> |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 22 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 23 | #ifdef HAVE_SYS_TYPES_H |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 25 | #endif /* HAVE_SYS_TYPES_H */ |
| 26 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 27 | #ifdef HAVE_SYS_STAT_H |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 28 | #include <sys/stat.h> |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 29 | #endif /* HAVE_SYS_STAT_H */ |
| 30 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 31 | #ifdef HAVE_FCNTL_H |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 32 | #include <fcntl.h> |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 33 | #endif /* HAVE_FCNTL_H */ |
| 34 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 35 | #ifdef HAVE_UNISTD_H |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 36 | # include <unistd.h> |
| 37 | #endif /* HAVE_UNISTD_H */ |
| 38 | |
| 39 | #ifdef WIN32 |
| 40 | # define WIN32_LEAN_AND_MEAN |
| 41 | # include <windows.h> |
| 42 | # include <io.h> |
| 43 | #endif /* defined(WIN32) */ |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 44 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 45 | #if !defined(HAVE_OPEN) && defined(WIN32) |
Michael Clark | 837240f | 2007-03-13 08:26:25 +0000 | [diff] [blame] | 46 | # define open _open |
| 47 | #endif |
| 48 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 49 | #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) |
| 50 | /* MSC has the version as _snprintf */ |
| 51 | # define snprintf _snprintf |
| 52 | #elif !defined(HAVE_SNPRINTF) |
| 53 | # error You do not have snprintf on your system. |
| 54 | #endif /* HAVE_SNPRINTF */ |
Michael Clark | 837240f | 2007-03-13 08:26:25 +0000 | [diff] [blame] | 55 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 56 | #include "debug.h" |
| 57 | #include "printbuf.h" |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 58 | #include "json_inttypes.h" |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 59 | #include "json_object.h" |
| 60 | #include "json_tokener.h" |
| 61 | #include "json_util.h" |
| 62 | |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 63 | static int sscanf_is_broken = 0; |
| 64 | static int sscanf_is_broken_testdone = 0; |
| 65 | static void sscanf_is_broken_test(void); |
| 66 | |
Michael Clark | 88ded9c | 2009-08-27 06:40:59 +0000 | [diff] [blame] | 67 | struct json_object* json_object_from_file(const char *filename) |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 68 | { |
| 69 | struct printbuf *pb; |
| 70 | struct json_object *obj; |
| 71 | char buf[JSON_FILE_BUF_SIZE]; |
| 72 | int fd, ret; |
| 73 | |
| 74 | if((fd = open(filename, O_RDONLY)) < 0) { |
Eric Haszlakiewicz | b3bce4d | 2013-06-29 15:31:18 -0500 | [diff] [blame] | 75 | MC_ERROR("json_object_from_file: error opening file %s: %s\n", |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 76 | filename, strerror(errno)); |
Eric Haszlakiewicz | eead1a7 | 2012-07-08 20:32:12 -0500 | [diff] [blame] | 77 | return NULL; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 78 | } |
| 79 | if(!(pb = printbuf_new())) { |
Michael Clark | bd0a567 | 2010-10-13 14:09:41 +0000 | [diff] [blame] | 80 | close(fd); |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 81 | MC_ERROR("json_object_from_file: printbuf_new failed\n"); |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 82 | return NULL; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 83 | } |
| 84 | while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) { |
| 85 | printbuf_memappend(pb, buf, ret); |
| 86 | } |
| 87 | close(fd); |
| 88 | if(ret < 0) { |
Eric Haszlakiewicz | b3bce4d | 2013-06-29 15:31:18 -0500 | [diff] [blame] | 89 | MC_ERROR("json_object_from_file: error reading file %s: %s\n", |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 90 | filename, strerror(errno)); |
| 91 | printbuf_free(pb); |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 92 | return NULL; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 93 | } |
| 94 | obj = json_tokener_parse(pb->buf); |
| 95 | printbuf_free(pb); |
| 96 | return obj; |
| 97 | } |
| 98 | |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 99 | /* extended "format and write to file" function */ |
| 100 | |
Pascal Bach | 20e4708 | 2013-08-13 18:24:23 +0200 | [diff] [blame] | 101 | int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags) |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 102 | { |
Michael Clark | 68cafad | 2009-01-06 22:56:57 +0000 | [diff] [blame] | 103 | const char *json_str; |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 104 | int fd, ret; |
| 105 | unsigned int wpos, wsize; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 106 | |
| 107 | if(!obj) { |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 108 | MC_ERROR("json_object_to_file: object is null\n"); |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | if((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) { |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 113 | MC_ERROR("json_object_to_file: error opening file %s: %s\n", |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 114 | filename, strerror(errno)); |
| 115 | return -1; |
| 116 | } |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 117 | |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 118 | if(!(json_str = json_object_to_json_string_ext(obj,flags))) { |
Michael Clark | f1ae67d | 2010-10-13 14:10:51 +0000 | [diff] [blame] | 119 | close(fd); |
| 120 | return -1; |
| 121 | } |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 122 | |
| 123 | wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */ |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 124 | wpos = 0; |
| 125 | while(wpos < wsize) { |
| 126 | if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) { |
| 127 | close(fd); |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 128 | MC_ERROR("json_object_to_file: error writing file %s: %s\n", |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 129 | filename, strerror(errno)); |
| 130 | return -1; |
| 131 | } |
Michael Clark | 4504df7 | 2007-03-13 08:26:20 +0000 | [diff] [blame] | 132 | |
| 133 | /* because of the above check for ret < 0, we can safely cast and add */ |
| 134 | wpos += (unsigned int)ret; |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | close(fd); |
| 138 | return 0; |
| 139 | } |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 140 | |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 141 | // backwards compatible "format and write to file" function |
| 142 | |
Pascal Bach | 20e4708 | 2013-08-13 18:24:23 +0200 | [diff] [blame] | 143 | int json_object_to_file(const char *filename, struct json_object *obj) |
Eric Haszlakiewicz | 3fcffe1 | 2012-04-28 13:26:09 -0500 | [diff] [blame] | 144 | { |
| 145 | return json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN); |
| 146 | } |
| 147 | |
Remi Collet | 16a4a32 | 2012-11-27 11:06:49 +0100 | [diff] [blame] | 148 | int json_parse_double(const char *buf, double *retval) |
| 149 | { |
Remi Collet | a01b659 | 2012-12-13 09:47:33 +0100 | [diff] [blame] | 150 | return (sscanf(buf, "%lf", retval)==1 ? 0 : 1); |
Remi Collet | 16a4a32 | 2012-11-27 11:06:49 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 153 | /* |
| 154 | * Not all implementations of sscanf actually work properly. |
| 155 | * Check whether the one we're currently using does, and if |
| 156 | * it's broken, enable the workaround code. |
| 157 | */ |
| 158 | static void sscanf_is_broken_test() |
| 159 | { |
| 160 | int64_t num64; |
Anatol Belski | 990fa8e | 2013-06-04 20:18:28 +0200 | [diff] [blame] | 161 | int ret_errno, is_int64_min, ret_errno2, is_int64_max; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 162 | |
| 163 | (void)sscanf(" -01234567890123456789012345", "%" SCNd64, &num64); |
Anatol Belski | 990fa8e | 2013-06-04 20:18:28 +0200 | [diff] [blame] | 164 | ret_errno = errno; |
| 165 | is_int64_min = (num64 == INT64_MIN); |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 166 | |
| 167 | (void)sscanf(" 01234567890123456789012345", "%" SCNd64, &num64); |
Anatol Belski | 990fa8e | 2013-06-04 20:18:28 +0200 | [diff] [blame] | 168 | ret_errno2 = errno; |
| 169 | is_int64_max = (num64 == INT64_MAX); |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 170 | |
| 171 | if (ret_errno != ERANGE || !is_int64_min || |
| 172 | ret_errno2 != ERANGE || !is_int64_max) |
| 173 | { |
| 174 | MC_DEBUG("sscanf_is_broken_test failed, enabling workaround code\n"); |
| 175 | sscanf_is_broken = 1; |
| 176 | } |
| 177 | } |
| 178 | |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 179 | int json_parse_int64(const char *buf, int64_t *retval) |
| 180 | { |
| 181 | int64_t num64; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 182 | const char *buf_sig_digits; |
John Arbash Meinel | 6a231e4 | 2012-02-01 09:27:49 +0100 | [diff] [blame] | 183 | int orig_has_neg; |
Greg Hazel | 77d0493 | 2013-01-03 16:54:04 -0800 | [diff] [blame] | 184 | int saved_errno; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 185 | |
| 186 | if (!sscanf_is_broken_testdone) |
| 187 | { |
| 188 | sscanf_is_broken_test(); |
| 189 | sscanf_is_broken_testdone = 1; |
| 190 | } |
| 191 | |
| 192 | // Skip leading spaces |
| 193 | while (isspace((int)*buf) && *buf) |
| 194 | buf++; |
| 195 | |
Eric Haszlakiewicz | 77c6239 | 2012-07-29 12:13:54 -0500 | [diff] [blame] | 196 | errno = 0; // sscanf won't always set errno, so initialize |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 197 | if (sscanf(buf, "%" SCNd64, &num64) != 1) |
| 198 | { |
ehaszla | 252669c | 2010-12-07 18:15:35 +0000 | [diff] [blame] | 199 | MC_DEBUG("Failed to parse, sscanf != 1\n"); |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 200 | return 1; |
| 201 | } |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 202 | |
Greg Hazel | 77d0493 | 2013-01-03 16:54:04 -0800 | [diff] [blame] | 203 | saved_errno = errno; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 204 | buf_sig_digits = buf; |
John Arbash Meinel | 6a231e4 | 2012-02-01 09:27:49 +0100 | [diff] [blame] | 205 | orig_has_neg = 0; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 206 | if (*buf_sig_digits == '-') |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 207 | { |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 208 | buf_sig_digits++; |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 209 | orig_has_neg = 1; |
| 210 | } |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 211 | |
| 212 | // Not all sscanf implementations actually work |
| 213 | if (sscanf_is_broken && saved_errno != ERANGE) |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 214 | { |
| 215 | char buf_cmp[100]; |
| 216 | char *buf_cmp_start = buf_cmp; |
| 217 | int recheck_has_neg = 0; |
John Arbash Meinel | 6a231e4 | 2012-02-01 09:27:49 +0100 | [diff] [blame] | 218 | int buf_cmp_len; |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 219 | |
| 220 | // Skip leading zeros, but keep at least one digit |
| 221 | while (buf_sig_digits[0] == '0' && buf_sig_digits[1] != '\0') |
| 222 | buf_sig_digits++; |
| 223 | if (num64 == 0) // assume all sscanf impl's will parse -0 to 0 |
| 224 | orig_has_neg = 0; // "-0" is the same as just plain "0" |
| 225 | |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 226 | snprintf(buf_cmp_start, sizeof(buf_cmp), "%" PRId64, num64); |
| 227 | if (*buf_cmp_start == '-') |
| 228 | { |
| 229 | recheck_has_neg = 1; |
| 230 | buf_cmp_start++; |
| 231 | } |
| 232 | // No need to skip leading spaces or zeros here. |
| 233 | |
John Arbash Meinel | 6a231e4 | 2012-02-01 09:27:49 +0100 | [diff] [blame] | 234 | buf_cmp_len = strlen(buf_cmp_start); |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 235 | /** |
| 236 | * If the sign is different, or |
| 237 | * some of the digits are different, or |
| 238 | * there is another digit present in the original string |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 239 | * then we have NOT successfully parsed the value. |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 240 | */ |
| 241 | if (orig_has_neg != recheck_has_neg || |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 242 | strncmp(buf_sig_digits, buf_cmp_start, strlen(buf_cmp_start)) != 0 || |
| 243 | ((int)strlen(buf_sig_digits) != buf_cmp_len && |
| 244 | isdigit((int)buf_sig_digits[buf_cmp_len]) |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 245 | ) |
| 246 | ) |
| 247 | { |
Greg Hazel | 77d0493 | 2013-01-03 16:54:04 -0800 | [diff] [blame] | 248 | saved_errno = ERANGE; |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
Eric Haszlakiewicz | bfb3292 | 2013-02-09 17:35:33 -0600 | [diff] [blame] | 251 | |
| 252 | // Not all sscanf impl's set the value properly when out of range. |
| 253 | // Always do this, even for properly functioning implementations, |
| 254 | // since it shouldn't slow things down much. |
Greg Hazel | 77d0493 | 2013-01-03 16:54:04 -0800 | [diff] [blame] | 255 | if (saved_errno == ERANGE) |
Michael Clark | c4dceae | 2010-10-06 16:39:20 +0000 | [diff] [blame] | 256 | { |
| 257 | if (orig_has_neg) |
| 258 | num64 = INT64_MIN; |
| 259 | else |
| 260 | num64 = INT64_MAX; |
| 261 | } |
| 262 | *retval = num64; |
| 263 | return 0; |
| 264 | } |
ehaszla | 252669c | 2010-12-07 18:15:35 +0000 | [diff] [blame] | 265 | |
Mateusz Loskot | a6f39a3 | 2012-05-21 23:22:36 +0100 | [diff] [blame] | 266 | #ifndef HAVE_REALLOC |
ehaszla | 252669c | 2010-12-07 18:15:35 +0000 | [diff] [blame] | 267 | void* rpl_realloc(void* p, size_t n) |
| 268 | { |
| 269 | if (n == 0) |
| 270 | n = 1; |
| 271 | if (p == 0) |
| 272 | return malloc(n); |
| 273 | return realloc(p, n); |
| 274 | } |
| 275 | #endif |
Eric Haszlakiewicz | 886c4fb | 2011-05-03 20:40:49 +0000 | [diff] [blame] | 276 | |
| 277 | #define NELEM(a) (sizeof(a) / sizeof(a[0])) |
| 278 | static const char* json_type_name[] = { |
| 279 | /* If you change this, be sure to update the enum json_type definition too */ |
| 280 | "null", |
| 281 | "boolean", |
| 282 | "double", |
| 283 | "int", |
| 284 | "object", |
| 285 | "array", |
| 286 | "string", |
| 287 | }; |
| 288 | |
| 289 | const char *json_type_to_name(enum json_type o_type) |
| 290 | { |
Eric Haszlakiewicz | ca8b27d | 2013-02-09 16:35:24 -0600 | [diff] [blame] | 291 | int o_type_int = (int)o_type; |
| 292 | if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name)) |
Eric Haszlakiewicz | 886c4fb | 2011-05-03 20:40:49 +0000 | [diff] [blame] | 293 | { |
| 294 | MC_ERROR("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name)); |
| 295 | return NULL; |
| 296 | } |
| 297 | return json_type_name[o_type]; |
| 298 | } |
| 299 | |