summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-12-23 14:14:24 +0100
committerGravatar Nikias Bassen2021-12-23 14:14:24 +0100
commit0a5f1cc10b62c1d059b2f4e60f5512ac3e15ff07 (patch)
tree1b76e34164d9d0086c95ce30556f8dc7ea551b28 /tools
parent91c533af1a906e32eea17eb344f218e45c32a554 (diff)
downloadlibplist-0a5f1cc10b62c1d059b2f4e60f5512ac3e15ff07.tar.gz
libplist-0a5f1cc10b62c1d059b2f4e60f5512ac3e15ff07.tar.bz2
plistutil: Check return values from plist API to print proper error messages
and return a meaningful exit code.
Diffstat (limited to 'tools')
-rw-r--r--tools/plistutil.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index bd83e92..28848fa 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -148,6 +148,8 @@ static options_t *parse_arguments(int argc, char *argv[])
int main(int argc, char *argv[])
{
int ret = 0;
+ int input_res = PLIST_ERR_UNKNOWN;
+ int output_res = PLIST_ERR_UNKNOWN;
FILE *iplist = NULL;
plist_t root_node = NULL;
char *plist_out = NULL;
@@ -251,24 +253,30 @@ int main(int argc, char *argv[])
// convert from binary to xml or vice-versa
if (plist_is_binary(plist_entire, read_size))
{
- plist_from_bin(plist_entire, read_size, &root_node);
- plist_to_xml(root_node, &plist_out, &size);
+ input_res = plist_from_bin(plist_entire, read_size, &root_node);
+ if (input_res == PLIST_ERR_SUCCESS) {
+ output_res = plist_to_xml(root_node, &plist_out, &size);
+ }
}
else
{
- plist_from_xml(plist_entire, read_size, &root_node);
- plist_to_bin(root_node, &plist_out, &size);
+ input_res = plist_from_xml(plist_entire, read_size, &root_node);
+ if (input_res == PLIST_ERR_SUCCESS) {
+ output_res = plist_to_bin(root_node, &plist_out, &size);
+ }
}
}
else
{
- plist_from_memory(plist_entire, read_size, &root_node);
- if (options->out_fmt == 1) {
- plist_to_bin(root_node, &plist_out, &size);
- } else if (options->out_fmt == 2) {
- plist_to_xml(root_node, &plist_out, &size);
- } else if (options->out_fmt == 3) {
- plist_to_json(root_node, &plist_out, &size, 0);
+ input_res = plist_from_memory(plist_entire, read_size, &root_node);
+ if (input_res == PLIST_ERR_SUCCESS) {
+ if (options->out_fmt == 1) {
+ output_res = plist_to_bin(root_node, &plist_out, &size);
+ } else if (options->out_fmt == 2) {
+ output_res = plist_to_xml(root_node, &plist_out, &size);
+ } else if (options->out_fmt == 3) {
+ output_res = plist_to_json(root_node, &plist_out, &size, 0);
+ }
}
}
plist_free(root_node);
@@ -293,9 +301,22 @@ int main(int argc, char *argv[])
free(plist_out);
}
- else {
- fprintf(stderr, "ERROR: Failed to convert input file.\n");
- ret = 2;
+
+ if (input_res == PLIST_ERR_SUCCESS) {
+ switch (output_res) {
+ case PLIST_ERR_SUCCESS:
+ break;
+ case PLIST_ERR_FORMAT:
+ fprintf(stderr, "ERROR: Input plist data is not compatible with output format.\n");
+ ret = 2;
+ break;
+ default:
+ fprintf(stderr, "ERROR: Failed to convert plist data (%d)\n", output_res);
+ ret = 1;
+ }
+ } else {
+ fprintf(stderr, "ERROR: Could not parse plist data (%d)\n", input_res);
+ ret = 1;
}
free(options);