summaryrefslogtreecommitdiffstats
path: root/src/oplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-05-22 18:46:02 +0200
committerGravatar Nikias Bassen2026-05-22 18:46:02 +0200
commit9711459dbed7d60bb00c7d2c052623e8489c88e1 (patch)
tree550cceb133bbff047ad5b8d7e0334596b252f7f2 /src/oplist.c
parent389fab9a07baf3913c4214425e86cca588d559a1 (diff)
downloadlibplist-9711459dbed7d60bb00c7d2c052623e8489c88e1.tar.gz
libplist-9711459dbed7d60bb00c7d2c052623e8489c88e1.tar.bz2
refactor: centralize formatting helpers and harden out-plutil
Diffstat (limited to 'src/oplist.c')
-rw-r--r--src/oplist.c65
1 files changed, 1 insertions, 64 deletions
diff --git a/src/oplist.c b/src/oplist.c
index 3c48b3a..292467f 100644
--- a/src/oplist.c
+++ b/src/oplist.c
@@ -39,8 +39,7 @@
39#include "strbuf.h" 39#include "strbuf.h"
40#include "time64.h" 40#include "time64.h"
41#include "hashtable.h" 41#include "hashtable.h"
42 42#include "common.h"
43#define MAC_EPOCH 978307200
44 43
45#ifdef DEBUG 44#ifdef DEBUG
46static int plist_ostep_debug = 0; 45static int plist_ostep_debug = 0;
@@ -93,30 +92,6 @@ static char* strndup(const char* str, size_t len)
93#endif 92#endif
94#endif 93#endif
95 94
96static size_t dtostr(char *buf, size_t bufsize, double realval)
97{
98 size_t len = 0;
99 if (isnan(realval)) {
100 len = snprintf(buf, bufsize, "nan");
101 } else if (isinf(realval)) {
102 len = snprintf(buf, bufsize, "%cinfinity", (realval > 0.0) ? '+' : '-');
103 } else if (realval == 0.0f) {
104 len = snprintf(buf, bufsize, "0.0");
105 } else {
106 size_t i = 0;
107 len = snprintf(buf, bufsize, "%.*g", 17, realval);
108 for (i = 0; buf && i < len; i++) {
109 if (buf[i] == ',') {
110 buf[i] = '.';
111 break;
112 } else if (buf[i] == '.') {
113 break;
114 }
115 }
116 }
117 return len;
118}
119
120static const char allowed_unquoted_chars[256] = { 95static const char allowed_unquoted_chars[256] = {
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -371,44 +346,6 @@ static plist_err_t node_to_openstep(node_t node, bytearray_t **outbuf, uint32_t
371 return PLIST_ERR_SUCCESS; 346 return PLIST_ERR_SUCCESS;
372} 347}
373 348
374#define PO10i_LIMIT (INT64_MAX/10)
375
376/* based on https://stackoverflow.com/a/4143288 */
377static int num_digits_i(int64_t i)
378{
379 int n;
380 int64_t po10;
381 n=1;
382 if (i < 0) {
383 i = (i == INT64_MIN) ? INT64_MAX : -i;
384 n++;
385 }
386 po10=10;
387 while (i>=po10) {
388 n++;
389 if (po10 > PO10i_LIMIT) break;
390 po10*=10;
391 }
392 return n;
393}
394
395#define PO10u_LIMIT (UINT64_MAX/10)
396
397/* based on https://stackoverflow.com/a/4143288 */
398static int num_digits_u(uint64_t i)
399{
400 int n;
401 uint64_t po10;
402 n=1;
403 po10=10;
404 while (i>=po10) {
405 n++;
406 if (po10 > PO10u_LIMIT) break;
407 po10*=10;
408 }
409 return n;
410}
411
412static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify, int coerce, hashtable_t *visited) 349static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify, int coerce, hashtable_t *visited)
413{ 350{
414 plist_data_t data; 351 plist_data_t data;