summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
authorGravatar Christophe Fergeau2016-05-12 02:55:01 +0200
committerGravatar Nikias Bassen2016-05-12 02:55:01 +0200
commit11d639f92f2c7067a0e7cc949f147abd506514ec (patch)
treefef75bcb253462541982c678d0b7260fc5141811 /src/plist.c
parent449e27bf754f903f856a741e163a9e4a0c8037b0 (diff)
downloadlibplist-11d639f92f2c7067a0e7cc949f147abd506514ec.tar.gz
libplist-11d639f92f2c7067a0e7cc949f147abd506514ec.tar.bz2
Implement plist_from_memory()
Rather than having everyone reimplement binary/XML plist detection by looking at the first bytes of the plist content, it's better to do this detection in libplist and hide that internal detail from library users.
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plist.c b/src/plist.c
index 3e69e2a..1ff17fc 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -58,6 +58,21 @@ PLIST_API int plist_is_binary(const char *plist_data, uint32_t length)
return (memcmp(plist_data, "bplist00", 8) == 0);
}
+
+PLIST_API void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist)
+{
+ if (length < 8) {
+ *plist = NULL;
+ return;
+ }
+
+ if (plist_is_binary(plist_data, length)) {
+ plist_from_bin(plist_data, length, plist);
+ } else {
+ plist_from_xml(plist_data, length, plist);
+ }
+}
+
plist_t plist_new_node(plist_data_t data)
{
return (plist_t) node_create(NULL, data);