diff options
| author | 2023-04-19 17:49:07 +0200 | |
|---|---|---|
| committer | 2023-04-19 17:49:07 +0200 | |
| commit | ce9ce43efd707a85cc792ff2cc417603a53d4d1d (patch) | |
| tree | 64c471946cc9e2da8a373db1c1c85fb41bc84265 /include/plist/plist.h | |
| parent | 3aa5f6a3a663a5f2694ec6fc8cdf9744b616e15e (diff) | |
| download | libplist-ce9ce43efd707a85cc792ff2cc417603a53d4d1d.tar.gz libplist-ce9ce43efd707a85cc792ff2cc417603a53d4d1d.tar.bz2 | |
Add plist_read_from_file() to interface, update plist_from_memory()
plist_read_from_file() is a convenience function that will open a
given file, checks its size, allocates a buffer large enough to
hold the full contents, and reads from file to fill the buffer.
Then, it calls plist_from_memory() to convert the data to plist
format.
A (breaking) change had to be made so that plist_from_memory() will
also return the parsed format in its 4th argument (if non-NULL).
Diffstat (limited to 'include/plist/plist.h')
| -rw-r--r-- | include/plist/plist.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index b635996..9b16c58 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -44,6 +44,7 @@ extern "C" | |||
| 44 | #include <stdint.h> | 44 | #include <stdint.h> |
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | /*{{{ deprecation macros */ | ||
| 47 | #ifdef __llvm__ | 48 | #ifdef __llvm__ |
| 48 | #if defined(__has_extension) | 49 | #if defined(__has_extension) |
| 49 | #if (__has_extension(attribute_deprecated_with_message)) | 50 | #if (__has_extension(attribute_deprecated_with_message)) |
| @@ -72,6 +73,7 @@ extern "C" | |||
| 72 | #define PLIST_WARN_DEPRECATED(x) | 73 | #define PLIST_WARN_DEPRECATED(x) |
| 73 | #pragma message("WARNING: You need to implement DEPRECATED for this compiler") | 74 | #pragma message("WARNING: You need to implement DEPRECATED for this compiler") |
| 74 | #endif | 75 | #endif |
| 76 | /*}}}*/ | ||
| 75 | 77 | ||
| 76 | #include <sys/types.h> | 78 | #include <sys/types.h> |
| 77 | #include <stdarg.h> | 79 | #include <stdarg.h> |
| @@ -819,7 +821,8 @@ extern "C" | |||
| 819 | 821 | ||
| 820 | /** | 822 | /** |
| 821 | * Import the #plist_t structure from memory data. | 823 | * Import the #plist_t structure from memory data. |
| 822 | * This method will look at the first bytes of plist_data | 824 | * |
| 825 | * This function will look at the first bytes of plist_data | ||
| 823 | * to determine if plist_data contains a binary, JSON, OpenStep, or XML plist | 826 | * to determine if plist_data contains a binary, JSON, OpenStep, or XML plist |
| 824 | * and tries to parse the data in the appropriate format. | 827 | * and tries to parse the data in the appropriate format. |
| 825 | * @note This is just a convenience function and the format detection is | 828 | * @note This is just a convenience function and the format detection is |
| @@ -831,9 +834,25 @@ extern "C" | |||
| 831 | * @param plist_data A pointer to the memory buffer containing plist data. | 834 | * @param plist_data A pointer to the memory buffer containing plist data. |
| 832 | * @param length Length of the buffer to read. | 835 | * @param length Length of the buffer to read. |
| 833 | * @param plist A pointer to the imported plist. | 836 | * @param plist A pointer to the imported plist. |
| 837 | * @param format If non-NULL, the #plist_format_t value pointed to will be set to the parsed format. | ||
| 838 | * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure | ||
| 839 | */ | ||
| 840 | plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format); | ||
| 841 | |||
| 842 | /** | ||
| 843 | * Import the #plist_t structure directly from file. | ||
| 844 | * | ||
| 845 | * This function will look at the first bytes of the file data | ||
| 846 | * to determine if it contains a binary, JSON, OpenStep, or XML plist | ||
| 847 | * and tries to parse the data in the appropriate format. | ||
| 848 | * Uses #plist_read_from_data() internally. | ||
| 849 | * | ||
| 850 | * @param filename The name of the file to parse. | ||
| 851 | * @param plist A pointer to the imported plist. | ||
| 852 | * @param format If non-NULL, the #plist_format_t value pointed to will be set to the parsed format. | ||
| 834 | * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure | 853 | * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure |
| 835 | */ | 854 | */ |
| 836 | plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); | 855 | plist_err_t plist_read_from_file(const char *filename, plist_t *plist, plist_format_t *format); |
| 837 | 856 | ||
| 838 | /** | 857 | /** |
| 839 | * Write the #plist_t structure to a NULL-terminated string using the given format and options. | 858 | * Write the #plist_t structure to a NULL-terminated string using the given format and options. |
