]> git.proxmox.com Git - libgit2.git/blob - src/sysdir.h
Merge pull request #3303 from libgit2/cmn/index-add-submodule
[libgit2.git] / src / sysdir.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_sysdir_h__
8 #define INCLUDE_sysdir_h__
9
10 #include "common.h"
11 #include "posix.h"
12 #include "buffer.h"
13
14 /**
15 * Find a "global" file (i.e. one in a user's home directory).
16 *
17 * @param path buffer to write the full path into
18 * @param filename name of file to find in the home directory
19 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
20 */
21 extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
22
23 /**
24 * Find an "XDG" file (i.e. one in user's XDG config path).
25 *
26 * @param path buffer to write the full path into
27 * @param filename name of file to find in the home directory
28 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
29 */
30 extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
31
32 /**
33 * Find a "system" file (i.e. one shared for all users of the system).
34 *
35 * @param path buffer to write the full path into
36 * @param filename name of file to find in the home directory
37 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
38 */
39 extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
40
41 /**
42 * Find template directory.
43 *
44 * @param path buffer to write the full path into
45 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
46 */
47 extern int git_sysdir_find_template_dir(git_buf *path);
48
49 typedef enum {
50 GIT_SYSDIR_SYSTEM = 0,
51 GIT_SYSDIR_GLOBAL = 1,
52 GIT_SYSDIR_XDG = 2,
53 GIT_SYSDIR_TEMPLATE = 3,
54 GIT_SYSDIR__MAX = 4,
55 } git_sysdir_t;
56
57 /**
58 * Configures global data for configuration file search paths.
59 *
60 * @return 0 on success, <0 on failure
61 */
62 extern int git_sysdir_global_init(void);
63
64 /**
65 * Get the search path for global/system/xdg files
66 *
67 * @param out pointer to git_buf containing search path
68 * @param which which list of paths to return
69 * @return 0 on success, <0 on failure
70 */
71 extern int git_sysdir_get(const git_buf **out, git_sysdir_t which);
72
73 /**
74 * Get search path into a preallocated buffer
75 *
76 * @param out String buffer to write into
77 * @param outlen Size of string buffer
78 * @param which Which search path to return
79 * @return 0 on success, GIT_EBUFS if out is too small, <0 on other failure
80 */
81
82 extern int git_sysdir_get_str(char *out, size_t outlen, git_sysdir_t which);
83
84 /**
85 * Set search paths for global/system/xdg files
86 *
87 * The first occurrence of the magic string "$PATH" in the new value will
88 * be replaced with the old value of the search path.
89 *
90 * @param which Which search path to modify
91 * @param paths New search path (separated by GIT_PATH_LIST_SEPARATOR)
92 * @return 0 on success, <0 on failure (allocation error)
93 */
94 extern int git_sysdir_set(git_sysdir_t which, const char *paths);
95
96 /**
97 * Free the configuration file search paths.
98 */
99 extern void git_sysdir_global_shutdown(void);
100
101 #endif /* INCLUDE_sysdir_h__ */