summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/plist.c b/src/plist.c
index 3f86105..4fc2f00 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -46,6 +46,8 @@
46#include <hashtable.h> 46#include <hashtable.h>
47#include <ptrarray.h> 47#include <ptrarray.h>
48 48
49#define MAC_EPOCH 978307200
50
49#ifdef _MSC_VER 51#ifdef _MSC_VER
50typedef SSIZE_T ssize_t; 52typedef SSIZE_T ssize_t;
51#endif 53#endif
@@ -528,6 +530,15 @@ plist_t plist_new_date(int32_t sec, int32_t usec)
528 return plist_new_node(data); 530 return plist_new_node(data);
529} 531}
530 532
533plist_t plist_new_unix_date(int64_t sec)
534{
535 plist_data_t data = plist_new_plist_data();
536 data->type = PLIST_DATE;
537 data->realval = (double)sec - MAC_EPOCH;
538 data->length = sizeof(double);
539 return plist_new_node(data);
540}
541
531plist_t plist_new_null(void) 542plist_t plist_new_null(void)
532{ 543{
533 plist_data_t data = plist_new_plist_data(); 544 plist_data_t data = plist_new_plist_data();
@@ -1392,6 +1403,20 @@ void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec)
1392 } 1403 }
1393} 1404}
1394 1405
1406void plist_get_unix_date_val(plist_t node, int64_t *sec)
1407{
1408 if (!node || !sec)
1409 return;
1410 plist_type type = plist_get_node_type(node);
1411 uint64_t length = 0;
1412 double val = 0;
1413 if (PLIST_DATE != type)
1414 return;
1415 plist_get_type_and_value(node, &type, (void *) &val, &length);
1416 assert(length == sizeof(double));
1417 *sec = (int64_t)val + MAC_EPOCH;
1418}
1419
1395int plist_data_compare(const void *a, const void *b) 1420int plist_data_compare(const void *a, const void *b)
1396{ 1421{
1397 plist_data_t val_a = NULL; 1422 plist_data_t val_a = NULL;
@@ -1551,6 +1576,12 @@ void plist_set_date_val(plist_t node, int32_t sec, int32_t usec)
1551 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double)); 1576 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double));
1552} 1577}
1553 1578
1579void plist_set_unix_date_val(plist_t node, int64_t sec)
1580{
1581 double val = (double)(sec - MAC_EPOCH);
1582 plist_set_element_val(node, PLIST_DATE, &val, sizeof(double));
1583}
1584
1554int plist_bool_val_is_true(plist_t boolnode) 1585int plist_bool_val_is_true(plist_t boolnode)
1555{ 1586{
1556 if (!PLIST_IS_BOOLEAN(boolnode)) { 1587 if (!PLIST_IS_BOOLEAN(boolnode)) {
@@ -1686,6 +1717,24 @@ int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec)
1686 return 1; 1717 return 1;
1687} 1718}
1688 1719
1720int plist_unix_date_val_compare(plist_t datenode, int64_t cmpval)
1721{
1722 if (!PLIST_IS_DATE(datenode)) {
1723 return -1;
1724 }
1725 int64_t dateval = 0;
1726 plist_get_unix_date_val(datenode, &dateval);
1727 if (dateval == cmpval) {
1728 return 0;
1729 }
1730
1731 if (dateval < cmpval) {
1732 return -1;
1733 }
1734
1735 return 1;
1736}
1737
1689int plist_string_val_compare(plist_t strnode, const char* cmpval) 1738int plist_string_val_compare(plist_t strnode, const char* cmpval)
1690{ 1739{
1691 if (!PLIST_IS_STRING(strnode)) { 1740 if (!PLIST_IS_STRING(strnode)) {