MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / print

Function print

external/cJSON/cJSON.c:1239–1304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1237#define cjson_min(a, b) (((a) < (b)) ? (a) : (b))
1238
1239static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
1240{
1241 static const size_t default_buffer_size = 256;
1242 printbuffer buffer[1];
1243 unsigned char *printed = NULL;
1244
1245 memset(buffer, 0, sizeof(buffer));
1246
1247 /* create buffer */
1248 buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
1249 buffer->length = default_buffer_size;
1250 buffer->format = format;
1251 buffer->hooks = *hooks;
1252 if (buffer->buffer == NULL)
1253 {
1254 goto fail;
1255 }
1256
1257 /* print the value */
1258 if (!print_value(item, buffer))
1259 {
1260 goto fail;
1261 }
1262 update_offset(buffer);
1263
1264 /* check if reallocate is available */
1265 if (hooks->reallocate != NULL)
1266 {
1267 printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
1268 if (printed == NULL) {
1269 goto fail;
1270 }
1271 buffer->buffer = NULL;
1272 }
1273 else /* otherwise copy the JSON over to a new buffer */
1274 {
1275 printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
1276 if (printed == NULL)
1277 {
1278 goto fail;
1279 }
1280 memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
1281 printed[buffer->offset] = '\0'; /* just to be sure */
1282
1283 /* free the buffer */
1284 hooks->deallocate(buffer->buffer);
1285 buffer->buffer = NULL;
1286 }
1287
1288 return printed;
1289
1290fail:
1291 if (buffer->buffer != NULL)
1292 {
1293 hooks->deallocate(buffer->buffer);
1294 buffer->buffer = NULL;
1295 }
1296

Callers 15

print_package_tableFunction · 0.85
install_nemo_archiveFunction · 0.85
command_listFunction · 0.85
command_infoFunction · 0.85
command_installFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
run_caseFunction · 0.85
mainFunction · 0.85

Calls 4

print_valueFunction · 0.85
update_offsetFunction · 0.85
allocateMethod · 0.45
deallocateMethod · 0.45

Tested by 4

run_caseFunction · 0.68
mainFunction · 0.68
test_immutable_protoMethod · 0.68
ctxFunction · 0.68