diff options
Diffstat (limited to 'src/out-limd.c')
| -rw-r--r-- | src/out-limd.c | 79 |
1 files changed, 1 insertions, 78 deletions
diff --git a/src/out-limd.c b/src/out-limd.c index 6d864cb..b01f966 100644 --- a/src/out-limd.c +++ b/src/out-limd.c | |||
| @@ -41,46 +41,7 @@ | |||
| 41 | #include "time64.h" | 41 | #include "time64.h" |
| 42 | #include "base64.h" | 42 | #include "base64.h" |
| 43 | #include "hashtable.h" | 43 | #include "hashtable.h" |
| 44 | 44 | #include "common.h" | |
| 45 | #define MAC_EPOCH 978307200 | ||
| 46 | |||
| 47 | static size_t dtostr(char *buf, size_t bufsize, double realval) | ||
| 48 | { | ||
| 49 | int slen = 0; | ||
| 50 | if (isnan(realval)) { | ||
| 51 | slen = snprintf(buf, bufsize, "nan"); | ||
| 52 | } else if (isinf(realval)) { | ||
| 53 | slen = snprintf(buf, bufsize, "%cinfinity", (realval > 0.0) ? '+' : '-'); | ||
| 54 | } else if (realval == 0.0f) { | ||
| 55 | slen = snprintf(buf, bufsize, "0.0"); | ||
| 56 | } else { | ||
| 57 | slen = snprintf(buf, bufsize, "%.*g", 17, realval); | ||
| 58 | if (slen < 0) { | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | if (!buf || bufsize == 0) { | ||
| 62 | return (size_t)slen; | ||
| 63 | } | ||
| 64 | size_t len = (size_t)slen; | ||
| 65 | if (len >= bufsize) { | ||
| 66 | len = bufsize - 1; | ||
| 67 | } | ||
| 68 | size_t i = 0; | ||
| 69 | for (i = 0; i < len; i++) { | ||
| 70 | if (buf[i] == ',') { | ||
| 71 | buf[i] = '.'; | ||
| 72 | break; | ||
| 73 | } else if (buf[i] == '.') { | ||
| 74 | break; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | return len; | ||
| 78 | } | ||
| 79 | if (slen < 0) { | ||
| 80 | return 0; | ||
| 81 | } | ||
| 82 | return (size_t)slen; | ||
| 83 | } | ||
| 84 | 45 | ||
| 85 | static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent) | 46 | static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent) |
| 86 | { | 47 | { |
| @@ -304,44 +265,6 @@ static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t de | |||
| 304 | return PLIST_ERR_SUCCESS; | 265 | return PLIST_ERR_SUCCESS; |
| 305 | } | 266 | } |
| 306 | 267 | ||
| 307 | #define PO10i_LIMIT (INT64_MAX/10) | ||
| 308 | |||
| 309 | /* based on https://stackoverflow.com/a/4143288 */ | ||
| 310 | static int num_digits_i(int64_t i) | ||
| 311 | { | ||
| 312 | int n; | ||
| 313 | int64_t po10; | ||
| 314 | n=1; | ||
| 315 | if (i < 0) { | ||
| 316 | i = (i == INT64_MIN) ? INT64_MAX : -i; | ||
| 317 | n++; | ||
| 318 | } | ||
| 319 | po10=10; | ||
| 320 | while (i>=po10) { | ||
| 321 | n++; | ||
| 322 | if (po10 > PO10i_LIMIT) break; | ||
| 323 | po10*=10; | ||
| 324 | } | ||
| 325 | return n; | ||
| 326 | } | ||
| 327 | |||
| 328 | #define PO10u_LIMIT (UINT64_MAX/10) | ||
| 329 | |||
| 330 | /* based on https://stackoverflow.com/a/4143288 */ | ||
| 331 | static int num_digits_u(uint64_t i) | ||
| 332 | { | ||
| 333 | int n; | ||
| 334 | uint64_t po10; | ||
| 335 | n=1; | ||
| 336 | po10=10; | ||
| 337 | while (i>=po10) { | ||
| 338 | n++; | ||
| 339 | if (po10 > PO10u_LIMIT) break; | ||
| 340 | po10*=10; | ||
| 341 | } | ||
| 342 | return n; | ||
| 343 | } | ||
| 344 | |||
| 345 | static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent, hashtable_t *visited) | 268 | static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent, hashtable_t *visited) |
| 346 | { | 269 | { |
| 347 | plist_data_t data; | 270 | plist_data_t data; |
