#include #include #include "../simple-xdg-bdirs.h" /* a simple example which attempts to read a value from a configuration file * and write it back to a cache file */ int main(int argc, char *argv[]) { char *s, *wdir, **rdirs, **cur; /* alloc a null-terminated array of directories in which to search for * configuration files */ rdirs = simple_xdg_bdirs_read_dirs(SIMPLE_XDG_BDIRS_CONFIG); /* in case of error, errno is set, so perror works */ if (rdirs == NULL) { perror(NULL); return 1; } /* search in the config directories for the given relative path. if not * found in the first, the second will be checked as a fallback etc */ s = simple_xdg_bdirs_fullpath_read("xdg_bdirs_test/config.conf", rdirs); /* element strings of rdirs must also be freed */ for (cur = rdirs; *cur != NULL; cur++) free(*cur); free(rdirs); /* check for errors again */ if (s == NULL) { perror(NULL); return 1; } /* print the fullpath of the file that was found */ puts(s); free(s); /* locate the directory into which runtime files should be written * (things like sockets or lock files) */ wdir = simple_xdg_bdirs_write_dir(SIMPLE_XDG_BDIRS_RUNTIME); if (wdir == NULL) { perror(NULL); return 1; } /* a convenience function that builds a fullpath from a relative path and * write directory */ s = simple_xdg_bdirs_fullpath_write("xdg_bdirs_test.lock", wdir); free(wdir); if (s == NULL) { perror(NULL); return 1; } puts(s); free(s); return 0; }