summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-04-19 17:49:07 +0200
committerGravatar Nikias Bassen2023-04-19 17:49:07 +0200
commitce9ce43efd707a85cc792ff2cc417603a53d4d1d (patch)
tree64c471946cc9e2da8a373db1c1c85fb41bc84265 /test
parent3aa5f6a3a663a5f2694ec6fc8cdf9744b616e15e (diff)
downloadlibplist-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 'test')
-rw-r--r--test/plist_cmp.c46
1 files changed, 2 insertions, 44 deletions
diff --git a/test/plist_cmp.c b/test/plist_cmp.c
index 4947276..c452032 100644
--- a/test/plist_cmp.c
+++ b/test/plist_cmp.c
@@ -75,21 +75,12 @@ static char compare_plist(plist_t node_l, plist_t node_r)
int main(int argc, char *argv[])
{
- FILE *iplist1 = NULL;
- FILE *iplist2 = NULL;
plist_t root_node1 = NULL;
plist_t root_node2 = NULL;
- char *plist_1 = NULL;
- char *plist_2 = NULL;
- int size_in1 = 0;
- int size_in2 = 0;
char *file_in1 = NULL;
char *file_in2 = NULL;
int res = 0;
- struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat));
- struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat));
-
if (argc!= 3)
{
printf("Wrong input\n");
@@ -99,36 +90,8 @@ int main(int argc, char *argv[])
file_in1 = argv[1];
file_in2 = argv[2];
- //read input file
- iplist1 = fopen(file_in1, "rb");
- iplist2 = fopen(file_in2, "rb");
-
- if (!iplist1 || !iplist2)
- {
- printf("File does not exists\n");
- return 2;
- }
-
- stat(file_in1, filestats1);
- stat(file_in2, filestats2);
-
- size_in1 = filestats1->st_size;
- size_in2 = filestats2->st_size;
-
- plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1));
- plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1));
-
- fread(plist_1, sizeof(char), size_in1, iplist1);
- fread(plist_2, sizeof(char), size_in2, iplist2);
-
- fclose(iplist1);
- fclose(iplist2);
-
- plist_1[size_in1] = '\0';
- plist_2[size_in2] = '\0';
-
- plist_from_memory(plist_1, size_in1, &root_node1);
- plist_from_memory(plist_2, size_in2, &root_node2);
+ plist_read_from_file(file_in1, &root_node1, NULL);
+ plist_read_from_file(file_in2, &root_node2, NULL);
if (!root_node1 || !root_node2)
{
@@ -142,11 +105,6 @@ int main(int argc, char *argv[])
plist_free(root_node1);
plist_free(root_node2);
- free(plist_1);
- free(plist_2);
- free(filestats1);
- free(filestats2);
-
return !res;
}