diff options
| author | 2021-12-22 03:17:26 +0100 | |
|---|---|---|
| committer | 2021-12-22 03:17:26 +0100 | |
| commit | 70f4a422e01910cdb783aac81f13c11223c3acbd (patch) | |
| tree | 1279c0edd8b84b91d6a9bc757ea5dc8232f4d78f /include | |
| parent | 810e1a5936867a9f2c9f07df3a33a9d02fc03466 (diff) | |
| download | libplist-70f4a422e01910cdb783aac81f13c11223c3acbd.tar.gz libplist-70f4a422e01910cdb783aac81f13c11223c3acbd.tar.bz2 | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/plist/plist.h | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index 0f69d40..21fd8bd 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -117,6 +117,15 @@ extern "C" | |||
| 117 | PLIST_NONE /**< No type */ | 117 | PLIST_NONE /**< No type */ |
| 118 | } plist_type; | 118 | } plist_type; |
| 119 | 119 | ||
| 120 | typedef enum | ||
| 121 | { | ||
| 122 | PLIST_ERR_SUCCESS = 0, /**< operation successful */ | ||
| 123 | PLIST_ERR_INVALID_ARG = -1, /**< one or more of the parameters are invalid */ | ||
| 124 | PLIST_ERR_FORMAT = -2, /**< the plist contains nodes not compatible with the output format */ | ||
| 125 | PLIST_ERR_PARSE = -3, /**< parsing of the input format failed */ | ||
| 126 | PLIST_ERR_NO_MEM = -4, /**< not enough memory to handle the operation */ | ||
| 127 | PLIST_ERR_UNKNOWN = -255 /**< an unspecified error occurred */ | ||
| 128 | } plist_err_t; | ||
| 120 | 129 | ||
| 121 | /******************************************** | 130 | /******************************************** |
| 122 | * * | 131 | * * |
| @@ -655,9 +664,10 @@ extern "C" | |||
| 655 | * @param plist_xml a pointer to a C-string. This function allocates the memory, | 664 | * @param plist_xml a pointer to a C-string. This function allocates the memory, |
| 656 | * caller is responsible for freeing it. Data is UTF-8 encoded. | 665 | * caller is responsible for freeing it. Data is UTF-8 encoded. |
| 657 | * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. | 666 | * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. |
| 667 | * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure | ||
| 658 | * @note Use plist_mem_free() to free the allocated memory. | 668 | * @note Use plist_mem_free() to free the allocated memory. |
| 659 | */ | 669 | */ |
| 660 | void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); | 670 | plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); |
| 661 | 671 | ||
| 662 | /** | 672 | /** |
| 663 | * Export the #plist_t structure to binary format. | 673 | * Export the #plist_t structure to binary format. |
| @@ -666,9 +676,10 @@ extern "C" | |||
| 666 | * @param plist_bin a pointer to a char* buffer. This function allocates the memory, | 676 | * @param plist_bin a pointer to a char* buffer. This function allocates the memory, |
| 667 | * caller is responsible for freeing it. | 677 | * caller is responsible for freeing it. |
| 668 | * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. | 678 | * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer. |
| 679 | * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure | ||
| 669 | * @note Use plist_mem_free() to free the allocated memory. | 680 | * @note Use plist_mem_free() to free the allocated memory. |
| 670 | */ | 681 | */ |
| 671 | void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); | 682 | plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); |
| 672 | 683 | ||
| 673 | /** | 684 | /** |
| 674 | * Import the #plist_t structure from XML format. | 685 | * Import the #plist_t structure from XML format. |
| @@ -676,8 +687,9 @@ extern "C" | |||
| 676 | * @param plist_xml a pointer to the xml buffer. | 687 | * @param plist_xml a pointer to the xml buffer. |
| 677 | * @param length length of the buffer to read. | 688 | * @param length length of the buffer to read. |
| 678 | * @param plist a pointer to the imported plist. | 689 | * @param plist a pointer to the imported plist. |
| 690 | * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure | ||
| 679 | */ | 691 | */ |
| 680 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist); | 692 | plist_err_t plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist); |
| 681 | 693 | ||
| 682 | /** | 694 | /** |
| 683 | * Import the #plist_t structure from binary format. | 695 | * Import the #plist_t structure from binary format. |
| @@ -685,8 +697,9 @@ extern "C" | |||
| 685 | * @param plist_bin a pointer to the xml buffer. | 697 | * @param plist_bin a pointer to the xml buffer. |
| 686 | * @param length length of the buffer to read. | 698 | * @param length length of the buffer to read. |
| 687 | * @param plist a pointer to the imported plist. | 699 | * @param plist a pointer to the imported plist. |
| 700 | * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure | ||
| 688 | */ | 701 | */ |
| 689 | void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); | 702 | plist_err_t plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); |
| 690 | 703 | ||
| 691 | /** | 704 | /** |
| 692 | * Import the #plist_t structure from memory data. | 705 | * Import the #plist_t structure from memory data. |
| @@ -696,8 +709,9 @@ extern "C" | |||
| 696 | * @param plist_data a pointer to the memory buffer containing plist data. | 709 | * @param plist_data a pointer to the memory buffer containing plist data. |
| 697 | * @param length length of the buffer to read. | 710 | * @param length length of the buffer to read. |
| 698 | * @param plist a pointer to the imported plist. | 711 | * @param plist a pointer to the imported plist. |
| 712 | * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure | ||
| 699 | */ | 713 | */ |
| 700 | void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); | 714 | plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); |
| 701 | 715 | ||
| 702 | /** | 716 | /** |
| 703 | * Test if in-memory plist data is binary or XML | 717 | * Test if in-memory plist data is binary or XML |
