| 1310 | } |
| 1311 | |
| 1312 | CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) |
| 1313 | { |
| 1314 | printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; |
| 1315 | |
| 1316 | if (prebuffer < 0) |
| 1317 | { |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | |
| 1321 | p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); |
| 1322 | if (!p.buffer) |
| 1323 | { |
| 1324 | return NULL; |
| 1325 | } |
| 1326 | |
| 1327 | p.length = (size_t)prebuffer; |
| 1328 | p.offset = 0; |
| 1329 | p.noalloc = false; |
| 1330 | p.format = fmt; |
| 1331 | p.hooks = global_hooks; |
| 1332 | |
| 1333 | if (!print_value(item, &p)) |
| 1334 | { |
| 1335 | global_hooks.deallocate(p.buffer); |
| 1336 | p.buffer = NULL; |
| 1337 | return NULL; |
| 1338 | } |
| 1339 | |
| 1340 | return (char*)p.buffer; |
| 1341 | } |
| 1342 | |
| 1343 | CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) |
| 1344 | { |
searching dependent graphs…