diff options
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 71 |
1 files changed, 6 insertions, 65 deletions
diff --git a/src/xplist.c b/src/xplist.c index de5227a..b2c134e 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -48,6 +48,7 @@ #include "strbuf.h" #include "time64.h" #include "hashtable.h" +#include "common.h" #define XPLIST_KEY "key" #define XPLIST_KEY_LEN 3 @@ -70,8 +71,6 @@ #define XPLIST_DICT "dict" #define XPLIST_DICT_LEN 4 -#define MAC_EPOCH 978307200 - #define MAX_DATA_BYTES_PER_LINE(__i) (((76 - ((__i) << 3)) >> 2) * 3) 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) #endif } -static size_t dtostr(char *buf, size_t bufsize, double realval) -{ - size_t len = 0; - if (isnan(realval)) { - len = snprintf(buf, bufsize, "nan"); - } else if (isinf(realval)) { - len = snprintf(buf, bufsize, "%cinfinity", (realval > 0.0) ? '+' : '-'); - } else if (realval == 0.0f) { - len = snprintf(buf, bufsize, "0.0"); - } else { - size_t i = 0; - len = snprintf(buf, bufsize, "%.*g", 17, realval); - for (i = 0; buf && i < len; i++) { - if (buf[i] == ',') { - buf[i] = '.'; - break; - } else if (buf[i] == '.') { - break; - } - } - } - return len; -} - static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth) { plist_data_t node_data = NULL; @@ -217,7 +192,11 @@ static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth tag = XPLIST_DATE; tag_len = XPLIST_DATE_LEN; { - Time64_T timev = (Time64_T)node_data->realval + MAC_EPOCH; + Time64_T timev; + if (plist_real_to_time64(node_data->realval, &timev) < 0) { + PLIST_XML_WRITE_ERR("Encountered invalid date value %f\n", node_data->realval); + return PLIST_ERR_INVALID_ARG; + } struct TM _btime; struct TM *btime = gmtime64_r(&timev, &_btime); if (btime) { @@ -422,44 +401,6 @@ static int parse_date(const char *strval, struct TM *btime) return 0; } -#define PO10i_LIMIT (INT64_MAX/10) - -/* based on https://stackoverflow.com/a/4143288 */ -static int num_digits_i(int64_t i) -{ - int n; - int64_t po10; - n=1; - if (i < 0) { - i = (i == INT64_MIN) ? INT64_MAX : -i; - n++; - } - po10=10; - while (i>=po10) { - n++; - if (po10 > PO10i_LIMIT) break; - po10*=10; - } - return n; -} - -#define PO10u_LIMIT (UINT64_MAX/10) - -/* based on https://stackoverflow.com/a/4143288 */ -static int num_digits_u(uint64_t i) -{ - int n; - uint64_t po10; - n=1; - po10=10; - while (i>=po10) { - n++; - if (po10 > PO10u_LIMIT) break; - po10*=10; - } - return n; -} - static plist_err_t _node_estimate_size(node_t node, uint64_t *size, uint32_t depth, hashtable_t *visited) { plist_data_t data; |
