Merge branch 'development', bumped version to 1.1.1, adjusted libtool version info.
[libxdg-basedir.git] / include / basedir_fs.h
blob35d1f5aa262d40ca17abc23f3569eaf34cf83587
1 /* Copyright (c) 2007 Mark Nevill
2 *
3 * Permission is hereby granted, free of charge, to any person
4 * obtaining a copy of this software and associated documentation
5 * files (the "Software"), to deal in the Software without
6 * restriction, including without limitation the rights to use,
7 * copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following
10 * conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 /** @file basedir_fs.h
26 * Filesystem functions related to the XDG Base Directory specification. */
28 #ifndef XDG_BASEDIR_FS_H
29 #define XDG_BASEDIR_FS_H
31 #include <basedir.h>
32 #include <stdio.h>
33 #include <sys/types.h>
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 /** @name Filesystem-related XDG Base Directory Queries */
40 /*@{*/
42 /** Find all existing data files corresponding to relativePath.
43 * Consider as performing @code fopen(filename, "r") @endcode on every possible @c filename
44 * and returning the successful <tt>filename</tt>s.
45 * @param relativePath Path to scan for.
46 * @param handle Handle to data cache, initialized with xdgInitHandle().
47 * @return A sequence of null-terminated strings terminated by a double-null (empty string)
48 * and allocated using malloc(), e.g.: @code "/etc/share\0/home/jdoe/.local\0" @endcode
50 char * xdgDataFind(const char* relativePath, xdgHandle *handle);
52 /** Find all existing config files corresponding to relativePath.
53 * Consider as performing @code fopen(filename, "r") @endcode on every possible @c filename
54 * and returning the successful <tt>filename</tt>s.
55 * @param relativePath Path to scan for.
56 * @param handle Handle to data cache, initialized with xdgInitHandle().
57 * @return A sequence of null-terminated strings terminated by a double-null (empty string)
58 * and allocated using malloc(), e.g.: @code "/etc/xdg\0/home/jdoe/.config\0" @endcode
60 char * xdgConfigFind(const char* relativePath, xdgHandle *handle);
62 /** Open first possible data file corresponding to relativePath.
63 * Consider as performing @code fopen(filename, mode) @endcode on every possible @c filename
64 * and returning the first successful @c filename or @c NULL.
65 * @param relativePath Path to scan for.
66 * @param mode Mode with which to attempt to open files (see fopen modes).
67 * @param handle Handle to data cache, initialized with xdgInitHandle().
68 * @return File pointer if successful else @c NULL. Client must use @c fclose to close file.
70 FILE * xdgDataOpen(const char* relativePath, const char* mode, xdgHandle *handle);
72 /** Open first possible config file corresponding to relativePath.
73 * Consider as performing @code fopen(filename, mode) @endcode on every possible @c filename
74 * and returning the first successful @c filename or @c NULL.
75 * @param relativePath Path to scan for.
76 * @param mode Mode with which to attempt to open files (see fopen modes).
77 * @param handle Handle to data cache, initialized with xdgInitHandle().
78 * @return File pointer if successful else @c NULL. Client must use @c fclose to close file.
80 FILE * xdgConfigOpen(const char* relativePath, const char* mode, xdgHandle *handle);
82 /** Create path by recursively creating directories.
83 * This utility function is not part of the XDG specification, but
84 * nevertheless useful in context of directory manipulation.
85 * @param path The path to be created.
86 * @param mode The permissions to use for created directories. This parameter
87 * is modified by the process's umask. For details, see mkdir(2)'s mode
88 * parameter.
89 * @return Zero on success, -1 if an error occured (in which case errno will
90 * be set appropriately)
92 int xdgMakePath(const char * path, mode_t mode);
94 /*@}*/
96 #ifdef __cplusplus
97 } // extern "C"
98 #endif
100 #endif /*XDG_BASEDIR_FS_H*/