summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c68
1 files changed, 60 insertions, 8 deletions
diff --git a/src/plist.c b/src/plist.c
index e696f70..5d06311 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -2,7 +2,7 @@
2 * plist.c 2 * plist.c
3 * Builds plist XML structures 3 * Builds plist XML structures
4 * 4 *
5 * Copyright (c) 2009-2019 Nikias Bassen, All Rights Reserved. 5 * Copyright (c) 2009-2023 Nikias Bassen, All Rights Reserved.
6 * Copyright (c) 2010-2015 Martin Szulecki, All Rights Reserved. 6 * Copyright (c) 2010-2015 Martin Szulecki, All Rights Reserved.
7 * Copyright (c) 2008 Zach C., All Rights Reserved. 7 * Copyright (c) 2008 Zach C., All Rights Reserved.
8 * 8 *
@@ -390,7 +390,16 @@ PLIST_API plist_t plist_new_bool(uint8_t val)
390PLIST_API plist_t plist_new_uint(uint64_t val) 390PLIST_API plist_t plist_new_uint(uint64_t val)
391{ 391{
392 plist_data_t data = plist_new_plist_data(); 392 plist_data_t data = plist_new_plist_data();
393 data->type = PLIST_UINT; 393 data->type = PLIST_INT;
394 data->intval = val;
395 data->length = (val > INT_MAX) ? sizeof(uint64_t)*2 : sizeof(uint64_t);
396 return plist_new_node(data);
397}
398
399PLIST_API plist_t plist_new_int(int64_t val)
400{
401 plist_data_t data = plist_new_plist_data();
402 data->type = PLIST_INT;
394 data->intval = val; 403 data->intval = val;
395 data->length = sizeof(uint64_t); 404 data->length = sizeof(uint64_t);
396 return plist_new_node(data); 405 return plist_new_node(data);
@@ -926,7 +935,7 @@ static void plist_get_type_and_value(plist_t node, plist_type * type, void *valu
926 case PLIST_BOOLEAN: 935 case PLIST_BOOLEAN:
927 *((char *) value) = data->boolval; 936 *((char *) value) = data->boolval;
928 break; 937 break;
929 case PLIST_UINT: 938 case PLIST_INT:
930 case PLIST_UID: 939 case PLIST_UID:
931 *((uint64_t *) value) = data->intval; 940 *((uint64_t *) value) = data->intval;
932 break; 941 break;
@@ -1024,12 +1033,17 @@ PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val)
1024 return; 1033 return;
1025 plist_type type = plist_get_node_type(node); 1034 plist_type type = plist_get_node_type(node);
1026 uint64_t length = 0; 1035 uint64_t length = 0;
1027 if (PLIST_UINT != type) 1036 if (PLIST_INT != type)
1028 return; 1037 return;
1029 plist_get_type_and_value(node, &type, (void *) val, &length); 1038 plist_get_type_and_value(node, &type, (void *) val, &length);
1030 assert(length == sizeof(uint64_t) || length == 16); 1039 assert(length == sizeof(uint64_t) || length == 16);
1031} 1040}
1032 1041
1042PLIST_API void plist_get_int_val(plist_t node, int64_t * val)
1043{
1044 plist_get_uint_val(node, (uint64_t*)val);
1045}
1046
1033PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val) 1047PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val)
1034{ 1048{
1035 if (!node || !val) 1049 if (!node || !val)
@@ -1116,7 +1130,7 @@ int plist_data_compare(const void *a, const void *b)
1116 switch (val_a->type) 1130 switch (val_a->type)
1117 { 1131 {
1118 case PLIST_BOOLEAN: 1132 case PLIST_BOOLEAN:
1119 case PLIST_UINT: 1133 case PLIST_INT:
1120 case PLIST_REAL: 1134 case PLIST_REAL:
1121 case PLIST_DATE: 1135 case PLIST_DATE:
1122 case PLIST_UID: 1136 case PLIST_UID:
@@ -1180,7 +1194,7 @@ static void plist_set_element_val(plist_t node, plist_type type, const void *val
1180 case PLIST_BOOLEAN: 1194 case PLIST_BOOLEAN:
1181 data->boolval = *((char *) value); 1195 data->boolval = *((char *) value);
1182 break; 1196 break;
1183 case PLIST_UINT: 1197 case PLIST_INT:
1184 case PLIST_UID: 1198 case PLIST_UID:
1185 data->intval = *((uint64_t *) value); 1199 data->intval = *((uint64_t *) value);
1186 break; 1200 break;
@@ -1225,7 +1239,12 @@ PLIST_API void plist_set_bool_val(plist_t node, uint8_t val)
1225 1239
1226PLIST_API void plist_set_uint_val(plist_t node, uint64_t val) 1240PLIST_API void plist_set_uint_val(plist_t node, uint64_t val)
1227{ 1241{
1228 plist_set_element_val(node, PLIST_UINT, &val, sizeof(uint64_t)); 1242 plist_set_element_val(node, PLIST_INT, &val, (val > INT64_MAX) ? sizeof(uint64_t)*2 : sizeof(uint64_t));
1243}
1244
1245PLIST_API void plist_set_int_val(plist_t node, int64_t val)
1246{
1247 plist_set_element_val(node, PLIST_INT, &val, sizeof(uint64_t));
1229} 1248}
1230 1249
1231PLIST_API void plist_set_uid_val(plist_t node, uint64_t val) 1250PLIST_API void plist_set_uid_val(plist_t node, uint64_t val)
@@ -1259,9 +1278,42 @@ PLIST_API int plist_bool_val_is_true(plist_t boolnode)
1259 return (bv == 1); 1278 return (bv == 1);
1260} 1279}
1261 1280
1281PLIST_API int plist_int_val_is_negative(plist_t intnode)
1282{
1283 if (!PLIST_IS_INT(intnode)) {
1284 return 0;
1285 }
1286 plist_data_t data = plist_get_data(intnode);
1287 if (data->length == 16) {
1288 return 0;
1289 }
1290 if ((int64_t)data->intval < 0) {
1291 return 1;
1292 }
1293 return 0;
1294}
1295
1296PLIST_API int plist_int_val_compare(plist_t uintnode, int64_t cmpval)
1297{
1298 if (!PLIST_IS_INT(uintnode)) {
1299 return -1;
1300 }
1301 int64_t uintval = 0;
1302 plist_get_int_val(uintnode, &uintval);
1303 if (uintval == cmpval) {
1304 return 0;
1305 }
1306
1307 if (uintval < cmpval) {
1308 return -1;
1309 }
1310
1311 return 1;
1312}
1313
1262PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval) 1314PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval)
1263{ 1315{
1264 if (!PLIST_IS_UINT(uintnode)) { 1316 if (!PLIST_IS_INT(uintnode)) {
1265 return -1; 1317 return -1;
1266 } 1318 }
1267 uint64_t uintval = 0; 1319 uint64_t uintval = 0;