From 70f4a422e01910cdb783aac81f13c11223c3acbd Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 22 Dec 2021 03:17:26 +0100 Subject: Add a return value to plist_to_* and plist_from_* functions This way it can be easier determined why an import/export operation failed instead of just having a NULL result. --- src/plist.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/plist.c') diff --git a/src/plist.c b/src/plist.c index 5453176..61b2913 100644 --- a/src/plist.c +++ b/src/plist.c @@ -183,18 +183,22 @@ PLIST_API int plist_is_binary(const char *plist_data, uint32_t length) } -PLIST_API void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist) +PLIST_API plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist) { - if (length < 8) { - *plist = NULL; - return; + int res = -1; + if (!plist) { + return PLIST_ERR_INVALID_ARG; + } + *plist = NULL; + if (!plist_data || length < 8) { + return PLIST_ERR_INVALID_ARG; } - if (plist_is_binary(plist_data, length)) { - plist_from_bin(plist_data, length, plist); + res = plist_from_bin(plist_data, length, plist); } else { - plist_from_xml(plist_data, length, plist); + res = plist_from_xml(plist_data, length, plist); } + return res; } plist_t plist_new_node(plist_data_t data) -- cgit v1.1-32-gdbae