diff options
| author | 2023-04-19 17:49:07 +0200 | |
|---|---|---|
| committer | 2023-04-19 17:49:07 +0200 | |
| commit | ce9ce43efd707a85cc792ff2cc417603a53d4d1d (patch) | |
| tree | 64c471946cc9e2da8a373db1c1c85fb41bc84265 /test/plist_cmp.c | |
| 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 'test/plist_cmp.c')
| -rw-r--r-- | test/plist_cmp.c | 46 |
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) | |||
| 75 | 75 | ||
| 76 | int main(int argc, char *argv[]) | 76 | int main(int argc, char *argv[]) |
| 77 | { | 77 | { |
| 78 | FILE *iplist1 = NULL; | ||
| 79 | FILE *iplist2 = NULL; | ||
| 80 | plist_t root_node1 = NULL; | 78 | plist_t root_node1 = NULL; |
| 81 | plist_t root_node2 = NULL; | 79 | plist_t root_node2 = NULL; |
| 82 | char *plist_1 = NULL; | ||
| 83 | char *plist_2 = NULL; | ||
| 84 | int size_in1 = 0; | ||
| 85 | int size_in2 = 0; | ||
| 86 | char *file_in1 = NULL; | 80 | char *file_in1 = NULL; |
| 87 | char *file_in2 = NULL; | 81 | char *file_in2 = NULL; |
| 88 | int res = 0; | 82 | int res = 0; |
| 89 | 83 | ||
| 90 | struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat)); | ||
| 91 | struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat)); | ||
| 92 | |||
| 93 | if (argc!= 3) | 84 | if (argc!= 3) |
| 94 | { | 85 | { |
| 95 | printf("Wrong input\n"); | 86 | printf("Wrong input\n"); |
| @@ -99,36 +90,8 @@ int main(int argc, char *argv[]) | |||
| 99 | file_in1 = argv[1]; | 90 | file_in1 = argv[1]; |
| 100 | file_in2 = argv[2]; | 91 | file_in2 = argv[2]; |
| 101 | 92 | ||
| 102 | //read input file | 93 | plist_read_from_file(file_in1, &root_node1, NULL); |
| 103 | iplist1 = fopen(file_in1, "rb"); | 94 | plist_read_from_file(file_in2, &root_node2, NULL); |
| 104 | iplist2 = fopen(file_in2, "rb"); | ||
| 105 | |||
| 106 | if (!iplist1 || !iplist2) | ||
| 107 | { | ||
| 108 | printf("File does not exists\n"); | ||
| 109 | return 2; | ||
| 110 | } | ||
| 111 | |||
| 112 | stat(file_in1, filestats1); | ||
| 113 | stat(file_in2, filestats2); | ||
| 114 | |||
| 115 | size_in1 = filestats1->st_size; | ||
| 116 | size_in2 = filestats2->st_size; | ||
| 117 | |||
| 118 | plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1)); | ||
| 119 | plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1)); | ||
| 120 | |||
| 121 | fread(plist_1, sizeof(char), size_in1, iplist1); | ||
| 122 | fread(plist_2, sizeof(char), size_in2, iplist2); | ||
| 123 | |||
| 124 | fclose(iplist1); | ||
| 125 | fclose(iplist2); | ||
| 126 | |||
| 127 | plist_1[size_in1] = '\0'; | ||
| 128 | plist_2[size_in2] = '\0'; | ||
| 129 | |||
| 130 | plist_from_memory(plist_1, size_in1, &root_node1); | ||
| 131 | plist_from_memory(plist_2, size_in2, &root_node2); | ||
| 132 | 95 | ||
| 133 | if (!root_node1 || !root_node2) | 96 | if (!root_node1 || !root_node2) |
| 134 | { | 97 | { |
| @@ -142,11 +105,6 @@ int main(int argc, char *argv[]) | |||
| 142 | plist_free(root_node1); | 105 | plist_free(root_node1); |
| 143 | plist_free(root_node2); | 106 | plist_free(root_node2); |
| 144 | 107 | ||
| 145 | free(plist_1); | ||
| 146 | free(plist_2); | ||
| 147 | free(filestats1); | ||
| 148 | free(filestats2); | ||
| 149 | |||
| 150 | return !res; | 108 | return !res; |
| 151 | } | 109 | } |
| 152 | 110 | ||
