diff options
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 65 |
1 files changed, 1 insertions, 64 deletions
diff --git a/src/xplist.c b/src/xplist.c index de5227a..8f5cb15 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | #include "strbuf.h" | 48 | #include "strbuf.h" |
| 49 | #include "time64.h" | 49 | #include "time64.h" |
| 50 | #include "hashtable.h" | 50 | #include "hashtable.h" |
| 51 | #include "common.h" | ||
| 51 | 52 | ||
| 52 | #define XPLIST_KEY "key" | 53 | #define XPLIST_KEY "key" |
| 53 | #define XPLIST_KEY_LEN 3 | 54 | #define XPLIST_KEY_LEN 3 |
| @@ -70,8 +71,6 @@ | |||
| 70 | #define XPLIST_DICT "dict" | 71 | #define XPLIST_DICT "dict" |
| 71 | #define XPLIST_DICT_LEN 4 | 72 | #define XPLIST_DICT_LEN 4 |
| 72 | 73 | ||
| 73 | #define MAC_EPOCH 978307200 | ||
| 74 | |||
| 75 | #define MAX_DATA_BYTES_PER_LINE(__i) (((76 - ((__i) << 3)) >> 2) * 3) | 74 | #define MAX_DATA_BYTES_PER_LINE(__i) (((76 - ((__i) << 3)) >> 2) * 3) |
| 76 | 75 | ||
| 77 | static const char XML_PLIST_PROLOG[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ | 76 | static const char XML_PLIST_PROLOG[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ |
| @@ -111,30 +110,6 @@ void plist_xml_set_debug(int debug) | |||
| 111 | #endif | 110 | #endif |
| 112 | } | 111 | } |
| 113 | 112 | ||
| 114 | static size_t dtostr(char *buf, size_t bufsize, double realval) | ||
| 115 | { | ||
| 116 | size_t len = 0; | ||
| 117 | if (isnan(realval)) { | ||
| 118 | len = snprintf(buf, bufsize, "nan"); | ||
| 119 | } else if (isinf(realval)) { | ||
| 120 | len = snprintf(buf, bufsize, "%cinfinity", (realval > 0.0) ? '+' : '-'); | ||
| 121 | } else if (realval == 0.0f) { | ||
| 122 | len = snprintf(buf, bufsize, "0.0"); | ||
| 123 | } else { | ||
| 124 | size_t i = 0; | ||
| 125 | len = snprintf(buf, bufsize, "%.*g", 17, realval); | ||
| 126 | for (i = 0; buf && i < len; i++) { | ||
| 127 | if (buf[i] == ',') { | ||
| 128 | buf[i] = '.'; | ||
| 129 | break; | ||
| 130 | } else if (buf[i] == '.') { | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | return len; | ||
| 136 | } | ||
| 137 | |||
| 138 | static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth) | 113 | static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth) |
| 139 | { | 114 | { |
| 140 | plist_data_t node_data = NULL; | 115 | plist_data_t node_data = NULL; |
| @@ -422,44 +397,6 @@ static int parse_date(const char *strval, struct TM *btime) | |||
| 422 | return 0; | 397 | return 0; |
| 423 | } | 398 | } |
| 424 | 399 | ||
| 425 | #define PO10i_LIMIT (INT64_MAX/10) | ||
| 426 | |||
| 427 | /* based on https://stackoverflow.com/a/4143288 */ | ||
| 428 | static int num_digits_i(int64_t i) | ||
| 429 | { | ||
| 430 | int n; | ||
| 431 | int64_t po10; | ||
| 432 | n=1; | ||
| 433 | if (i < 0) { | ||
| 434 | i = (i == INT64_MIN) ? INT64_MAX : -i; | ||
| 435 | n++; | ||
| 436 | } | ||
| 437 | po10=10; | ||
| 438 | while (i>=po10) { | ||
| 439 | n++; | ||
| 440 | if (po10 > PO10i_LIMIT) break; | ||
| 441 | po10*=10; | ||
| 442 | } | ||
| 443 | return n; | ||
| 444 | } | ||
| 445 | |||
| 446 | #define PO10u_LIMIT (UINT64_MAX/10) | ||
| 447 | |||
| 448 | /* based on https://stackoverflow.com/a/4143288 */ | ||
| 449 | static int num_digits_u(uint64_t i) | ||
| 450 | { | ||
| 451 | int n; | ||
| 452 | uint64_t po10; | ||
| 453 | n=1; | ||
| 454 | po10=10; | ||
| 455 | while (i>=po10) { | ||
| 456 | n++; | ||
| 457 | if (po10 > PO10u_LIMIT) break; | ||
| 458 | po10*=10; | ||
| 459 | } | ||
| 460 | return n; | ||
| 461 | } | ||
| 462 | |||
| 463 | static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, hashtable_t *visited) | 400 | static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, hashtable_t *visited) |
| 464 | { | 401 | { |
| 465 | plist_data_t data; | 402 | plist_data_t data; |
