Fixed bug in testfind.c
[libxdg-basedir.git] / tests / testfind.c
blob4485da748370ec1b4a9891e281a8f811cbc1d34b
1 #include <stdio.h>
2 #include <string.h>
3 #include <basedir.h>
5 void printAndFreeStrings(const char * strings)
7 const char * ptr = strings;
8 if (!strings) return;
9 while (*ptr)
11 printf("%s\n", ptr);
12 ptr += strlen(ptr)+1;
14 free(strings);
17 int main(int argc, char* argv[])
19 const char* result;
20 xdgHandle handle = xdgAllocHandle();
21 if (!handle) return 1;
23 if (argc == 2)
25 printf("xdgDataFind:\n");
26 printAndFreeStrings(xdgDataFind(argv[1], handle));
27 printf("xdgConfigFind:\n");
28 printAndFreeStrings(xdgConfigFind(argv[1], handle));
30 else if (argc == 3)
32 if (strcmp(argv[1], "--data") == 0)
33 printAndFreeStrings(xdgDataFind(argv[2], handle));
34 else if (strcmp(argv[1], "--config") == 0)
35 printAndFreeStrings(xdgConfigFind(argv[2], handle));
36 else
37 return 2;
39 else
40 return 2;
42 return 0;