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 12 #include "posix.h" 13 #include "buffer.h" 14 15 /** 16 * Find a "global" file (i.e. one in a user's home directory). 17 * 18 * @param path buffer to write the full path into 19 * @param filename name of file to find in the home directory 20 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error 21 */ 22 extern int git_sysdir_find_global_file(git_buf *path, const char *filename); 23 24 /** 25 * Find an "XDG" file (i.e. one in user's XDG config path). 26 * 27 * @param path buffer to write the full path into 28 * @param filename name of file to find in the home directory 29 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error 30 */ 31 extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename); 32 33 /** 34 * Find a "system" file (i.e. one shared for all users of the system). 35 * 36 * @param path buffer to write the full path into 37 * @param filename name of file to find in the home directory 38 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error 39 */ 40 extern int git_sysdir_find_system_file(git_buf *path, const char *filename); 41 42 /** 43 * Find a "ProgramData" file (i.e. one in %PROGRAMDATA%) 44 * 45 * @param path buffer to write the full path into 46 * @param filename name of file to find in the ProgramData directory 47 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error 48 */ 49 extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename); 50 51 /** 52 * Find template directory. 53 * 54 * @param path buffer to write the full path into 55 * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error 56 */ 57 extern int git_sysdir_find_template_dir(git_buf *path); 58 59 /** 60 * Expand the name of a "global" file (i.e. one in a user's home 61 * directory). Unlike `find_global_file` (above), this makes no 62 * attempt to check for the existence of the file, and is useful if 63 * you want the full path regardless of existence. 64 * 65 * @param path buffer to write the full path into 66 * @param filename name of file in the home directory 67 * @return 0 on success or -1 on error 68 */ 69 extern int git_sysdir_expand_global_file(git_buf *path, const char *filename); 70 71 typedef enum { 72 GIT_SYSDIR_SYSTEM = 0, 73 GIT_SYSDIR_GLOBAL = 1, 74 GIT_SYSDIR_XDG = 2, 75 GIT_SYSDIR_PROGRAMDATA = 3, 76 GIT_SYSDIR_TEMPLATE = 4, 77 GIT_SYSDIR__MAX = 5, 78 } git_sysdir_t; 79 80 /** 81 * Configures global data for configuration file search paths. 82 * 83 * @return 0 on success, <0 on failure 84 */ 85 extern int git_sysdir_global_init(void); 86 87 /** 88 * Get the search path for global/system/xdg files 89 * 90 * @param out pointer to git_buf containing search path 91 * @param which which list of paths to return 92 * @return 0 on success, <0 on failure 93 */ 94 extern int git_sysdir_get(const git_buf **out, git_sysdir_t which); 95 96 /** 97 * Set search paths for global/system/xdg files 98 * 99 * The first occurrence of the magic string "$PATH" in the new value will 100 * be replaced with the old value of the search path. 101 * 102 * @param which Which search path to modify 103 * @param paths New search path (separated by GIT_PATH_LIST_SEPARATOR) 104 * @return 0 on success, <0 on failure (allocation error) 105 */ 106 extern int git_sysdir_set(git_sysdir_t which, const char *paths); 107 108 #endif 109